package com.njzscloud.dispose.dev;

import com.njzscloud.common.core.tuple.Tuple2;
import com.njzscloud.common.mqtt.support.MqttListener;
import com.njzscloud.common.mqtt.support.MqttMsg;
import org.springframework.stereotype.Component;

import static com.njzscloud.dispose.dev.DevMittEvent.DISCOVER_TRUCK;
import static com.njzscloud.dispose.dev.DevMittEvent.OBTAIN_TRUCK_DATA_REPLY;

@Component
public class Wbs {
    @MqttListener(topic = "wbs/discover_truck")
    public void discoverTruck(MqttMsg msg) {
        DiscoverTruckMsg discoverTruckMsg = msg.getMsg(DiscoverTruckMsg.class);
        WbsHandle wbsHandle = new WbsHandle(discoverTruckMsg.getId(),
            discoverTruckMsg.getSn(),
            discoverTruckMsg.getGroupSn(),
            discoverTruckMsg.getBarrierSn());
        DISCOVER_TRUCK.emit(Tuple2.of(discoverTruckMsg, wbsHandle));
    }


    @MqttListener(topic = "wbs/obtain_truck_data/reply")
    public void obtainTruckDataReply(MqttMsg msg) {
        ObtainTruckDataResultMsg obtainTruckDataResultMsg = msg.getMsg(ObtainTruckDataResultMsg.class);
        WbsHandle wbsHandle = new WbsHandle(obtainTruckDataResultMsg.getId(),
            obtainTruckDataResultMsg.getSn(),
            obtainTruckDataResultMsg.getGroupSn(),
            obtainTruckDataResultMsg.getBarrierSn());
        OBTAIN_TRUCK_DATA_REPLY.emit(Tuple2.of(obtainTruckDataResultMsg, wbsHandle));
    }


}
