package com.its.dsrc.xnettcp.dsrc.process.response;

import com.beanit.asn1dsrc.dsrc.C2CAuthenticatedMessage;
import com.beanit.asn1dsrc.enums.eTerminate;
import com.its.app.utils.NettyUtils;
import com.its.dsrc.config.RunningConfig;
import com.its.dsrc.entity.TbRseCtlr;
import com.its.dsrc.xnettcp.dsrc.process.service.ControlDeviceService;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TerminateResponse implements DsrcAsn1Response {
    private TbRseCtlr obj;
    private ChannelHandlerContext ctx;
    private C2CAuthenticatedMessage c2c;

    public TerminateResponse(TbRseCtlr obj, ChannelHandlerContext ctx, C2CAuthenticatedMessage c2c) {
        this.obj = obj;
        this.ctx = ctx;
        this.c2c = c2c;
    }

    @Override
    public boolean response(RunningConfig runningConfig) {
        if (this.obj == null) {
            return false;
        }

        // 처리내용 없음.
        String ipAddress = NettyUtils.getRemoteIpAddress(this.ctx.channel());
        log.info("TerminateResponse.response: {}", ipAddress);

        //Terminate terminate = new Terminate(eTerminate.Terminate_ClientCommProblesm.getValue());
        ControlDeviceService.getInstance().sendTerminate(this.obj, this.ctx.channel(), eTerminate.Terminate_Other.getValue());
        return true;
    }
}
