package com.jsowell.netty.handler;

import com.alibaba.fastjson2.JSONObject;
import com.google.common.primitives.Bytes;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.netty.factory.YKCOperateFactory;
import com.jsowell.pile.service.impl.YKCPushCommandServiceImpl;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 读取实时监测数据（服务器端向桩发送消息 0x12）
 *
 * @deprecated 桩不会发送这个指令，由平台主动发送
 * @author JS-ZZA
 * @date 2022/9/19 8:43
 */
@Slf4j
@Component
public class ReadRealTimeMonitorDataHandler extends AbstractHandler{
    private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.READ_REAL_TIME_MONITOR_DATA_CODE.getBytes());

    @Autowired
    private YKCPushCommandServiceImpl ykcPushBusinessServiceImpl;


    @Override
    public void afterPropertiesSet() throws Exception {
        YKCOperateFactory.register(type, this);
    }

    @Override
    public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) {
        log.info("[===读取实时监测数据===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString());
        // 下发
        // 桩编号
        byte[] pileSnByteArr = new byte[]{};
        String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
        // 枪号
        byte[] pileConnectorByteArr = Constants.oneByteArray;

        // 拼接消息体
        byte[] msg = Bytes.concat(pileSnByteArr, pileConnectorByteArr);
        // push消息
        // boolean result = ykcPushBusinessServiceImpl.push(msg, pileSn, YKCFrameTypeCode.READ_REAL_TIME_MONITOR_DATA_CODE);

        // log.info(String.valueOf(result));

        return null;
    }
}
