package com.its.vds.xnettcp.vds.protocol.impl;

import com.its.vds.dto.TbVdsCtlrDto;
import com.its.vds.xnettcp.vds.protocol.VdsFramePacket;
import com.its.vds.xnettcp.vds.protocol.VdsReqFramePacket;
import com.its.vds.xnettcp.vds.protocol.enums.eVdsOpCode;
import com.its.vds.xnettcp.vds.protocol.impl.andong.VdsAndongFramePacket;
import lombok.extern.slf4j.Slf4j;

import java.nio.ByteBuffer;

/**
 * VDS Synchronization 요청(응답없음)
 */
@Slf4j
public class VdsReqSynchronization extends VdsReqFramePacket {

    private final VdsFramePacket framePacket;

    public VdsReqSynchronization(TbVdsCtlrDto vdsObj, byte[] schedule) {
        this.opCode = eVdsOpCode.OP_VDS_SYNCHRONIZATION;
        this.packetNmbr = (short)this.opCode.getValue();
        byte opCode = (byte)this.opCode.getValue();
        this.packetNmbr = vdsObj.getSeqNext();
        this.framePacket = new VdsAndongFramePacket(vdsObj.getGroupNo().intValue(), vdsObj.getVdsCtlrNmbr().intValue(), this.packetNmbr, opCode);

        makeBody(schedule);
    }

    public void makeBody(byte[] schedule) {
        byte[] body = new byte[schedule.length];
        System.arraycopy(schedule, 0, body, 0, body.length);
        this.framePacket.setBody(body);
    }

    @Override
    public ByteBuffer getByteBuffer() {
        return this.framePacket.getByteBuffer();
    }

}
