package vip.xiaonuo.coldchain.core.service.dataprocess.dataclean.impl;

import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;
import rk.netDevice.sdk.p2.NodeData;
import rk.netDevice.sdk.p2.RealTimeData;
import vip.xiaonuo.coldchain.core.bean.influxdb.SensorData;
import vip.xiaonuo.coldchain.core.service.dataprocess.dataclean.MonitorDataProcessor;
import vip.xiaonuo.coldchain.core.service.dataprocess.model.PowerEnum;
import vip.xiaonuo.coldchain.modular.monitordevice.enums.DeviceModelEnum;

import java.util.List;

/**
 * @author jackzhou
 * @version 1.0
 * @project jfcloud-coldchain
 * @description
 * @date 2024/11/20 21:25:30
 */
@Slf4j
@Component(MonitorDataProcessor.RS_WD_WIFI_6_5WL)
public class WifiLowTempRecorderProcessor1 extends AbsRenkeMonitorDataProcessor {
    public WifiLowTempRecorderProcessor1(ApplicationEventPublisher applicationEventPublisher) {
        super(applicationEventPublisher);
    }

    @Override
    List<SensorData> transRealTimeData2SensorDatas(@NotNull RealTimeData data) {
        List<NodeData> nodeList = data.getNodeList();
        final int numNodes = nodeList.size();
        if (numNodes == 0) {
            return Lists.newArrayList();
        }
        NodeData nodeData = nodeList.get(0);
        // 最后一路的温度的值0=电源供电  100 电池供电
        final String plugInStatus = nodeList.get(numNodes - 1).getTem() < 1 ? PowerEnum.AC.getCode() : PowerEnum.DC.getCode();
        SensorData sensorData = defaultSensorData(data);
        sensorData.setTemperature(floatValue(nodeData.getTem()));
        sensorData.setHumidity(floatValue(nodeData.getHum()));
        sensorData.setPlugInStatus(plugInStatus);
        sensorData.setRoads(1);
        return Lists.newArrayList(sensorData);
    }

    @Override
    DeviceModelEnum deviceModel() {
        return DeviceModelEnum.WIFI_MULTI_PROBE_TEMP_HUMIDITY_RECORDER_1;
    }
}
