package com.its.op.xnetudp.protocol;

import com.its.op.dto.its.vms.VmsControlDto;
import com.its.utils.SysUtils;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class CENTER_VMS_REQ_IMM_SCNR_DNLD extends CENTER_VMS_REQ_COMMON {

	private byte Count;
	private Long vmsCtlrNmbr;

	public CENTER_VMS_REQ_IMM_SCNR_DNLD(Long id, VmsControlDto.VmsControlReq req) {
		super(CENTER_COMM_DEFINE.INT_OP_VMS_IMMEDIATE_SCN_DNLD, 0x80, 0, id, req.getUserId(), null);
		this.Count = 1;
		this.vmsCtlrNmbr = id;
	}

	@Override
	public ByteBuffer getBuffer() {
		int pktSize = CENTER_COMM_DEFINE.INT_VMS_MAX_DATETIME + CENTER_COMM_DEFINE.INT_VMS_MAX_OPER_ID + 1 + 4;

		setLength(pktSize);

		ByteBuffer byteBuffer = ByteBuffer.allocate(CENTER_HEADER_SIZE + getLength());
		byteBuffer.order(ByteOrder.LITTLE_ENDIAN);

		byteBuffer.put(getSendId());
		byteBuffer.put(getRecvId());
		byteBuffer.put(getTotalFrame());
		byteBuffer.put(getCurrentFrame());
		byteBuffer.put(getMsgSeq());
		byteBuffer.put(getOpCode());
		byteBuffer.putShort(getLength());

		byte[] cmdTimeArr = new byte[CENTER_COMM_DEFINE.INT_VMS_MAX_DATETIME];
		byte[] operIdArr = new byte[CENTER_COMM_DEFINE.INT_VMS_MAX_OPER_ID];

		SysUtils.copyStringToByteArray(cmdTimeArr, cmdTimeArr.length, getCmdTime());
		SysUtils.copyStringToByteArray(operIdArr, operIdArr.length, getOperId());

		byteBuffer.put(cmdTimeArr);
		byteBuffer.put(operIdArr);

		byteBuffer.put(this.Count);

		//byte[] vmsIdArr = new byte[CENTER_COMM_DEFINE.INT_VMS_MAX_ID];
		//SysUtils.copyStringToByteArray(vmsIdArr, vmsIdArr.length, String.valueOf(getVmsCtlrNmbr()));
		//byteBuffer.put(vmsIdArr);
		byteBuffer.putInt(getVmsCtlrNmbr().intValue());

		return byteBuffer;

	}

}
