package com.njzscloud.common.localizer.mqtt;

import com.njzscloud.common.localizer.mqtt.param.*;
import com.njzscloud.common.localizer.tuqiang.Tuqiang;
import com.njzscloud.common.mqtt.support.MqttListener;
import com.njzscloud.common.mqtt.support.MqttMsg;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MqttMsgHandlers {

    /**
     * 开启追踪
     */
    @MqttListener(topic = "location/track")
    public void onMessage(MqttMsg msg) {
        LocationTrackParam locationTrackParam = msg.getMsg(LocationTrackParam.class);
        Tuqiang.track(locationTrackParam.getTerminalId(), locationTrackParam.getInterval());
    }

    /**
     * 获取当前位置
     */
    @MqttListener(topic = "location/current")
    public void currentLocation(MqttMsg msg) {
        LocationCurrentParam locationCurrentParam = msg.getMsg(LocationCurrentParam.class);
        Tuqiang.currentLocation(locationCurrentParam.getTerminalId());
    }

    /**
     * 启用报警
     */
    @MqttListener(topic = "location/warn")
    public void enableWarn(MqttMsg msg) {
        EnableWarnParam enableWarnParam = msg.getMsg(EnableWarnParam.class);
        String terminalId = enableWarnParam.getTerminalId();
        boolean enable = enableWarnParam.isEnable();
        Tuqiang.enableWarn(terminalId, enable);
    }

    /**
     * 设置速度阈值
     */
    @MqttListener(topic = "location/speed_threshold")
    public void speedThreshold(MqttMsg msg) {
        SpeedThresholdParam speedThresholdParam = msg.getMsg(SpeedThresholdParam.class);
        String terminalId = speedThresholdParam.getTerminalId();
        int speed = speedThresholdParam.getSpeed();
        Tuqiang.speedThreshold(terminalId, speed);
    }

    /**
     * 获取设备信息
     */
    @MqttListener(topic = "location/device_info")
    public void obtainDeviceInfo(MqttMsg msg) {
        ObtainDeviceInfoParam obtainDeviceInfoParam = msg.getMsg(ObtainDeviceInfoParam.class);
        String terminalId = obtainDeviceInfoParam.getTerminalId();
        Tuqiang.obtainDeviceInfo(terminalId);
    }
}
