package com.its.vms.domain.task;

import com.its.vms.dto.TbVmsCtlrDto;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;

import java.util.TimerTask;

@Slf4j
public class VmsTimeoutTask extends TimerTask {

    private final TbVmsCtlrDto obj;
    private final Long      packetNmbr;

    public VmsTimeoutTask(TbVmsCtlrDto obj, Long packetNmbr) {
        this.obj = obj;
        this.packetNmbr = packetNmbr;
    }

    @Override
    public void run() {

        MDC.put("id", this.obj.getLogKey());

        log.info("VmsTimeoutTask-run: packetNmbr: {}, obj: {}", this.packetNmbr, this.obj.getVmsCtlrNmbr());
//        this.obj.removeRegisteredCommands(this.packetNmbr, false);
//        TbVmsCtrlHs command = this.obj.getUserCommands(this.packetNmbr);
//        if (command != null) {
//            this.obj.removeUserCommands(this.packetNmbr);
//            // TODO: 제어명령 성공 전송(실패)
//            //command.setRspsType("5");  // 명령 실패(타임아웃)로 설정
//            VmsCtlrMapper mapper = (VmsCtlrMapper) AppUtils.getBean(VmsCtlrMapper.class);
//            mapper.updateVmsCtrlHs(command);
//        }

        MDC.remove(this.obj.getLogKey());
        MDC.clear();
    }
}
