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_PARAM extends CENTER_VMS_REQ_COMMON {

	private Long vmsCtlrNmbr;
	private byte FanRunTmpr;                              /* Fan동작 기준온도 */
	private byte HetrRunTmpr;                           /* Heater동작 기준온도 */
	private String DispStrTm;
	private String DispEndTm;

	public CENTER_VMS_REQ_PARAM(Long id, VmsControlDto.VmsControlParamReq req) {
		super(CENTER_COMM_DEFINE.INT_OP_VMS_PARA_SET, 0x40, 0, id, req.getUserId(), null);

		this.vmsCtlrNmbr = id;
		this.FanRunTmpr = (byte)req.getFanRunTmpr().intValue();
		this.HetrRunTmpr = (byte)req.getHetrRunTmpr().intValue();
		this.DispStrTm = req.getPanlOnTime();
		this.DispEndTm = req.getPanlOffTime();
	}

	@Override
	public ByteBuffer getBuffer() {
		int pktSize = CENTER_COMM_DEFINE.INT_VMS_MAX_DATETIME + CENTER_COMM_DEFINE.INT_VMS_MAX_OPER_ID + 4 + 1 + 1 + 4 + 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.putInt(this.vmsCtlrNmbr.intValue());
		byteBuffer.put(this.FanRunTmpr);
		byteBuffer.put(this.HetrRunTmpr);

		byte[] panlOnTime = new byte[4];
		SysUtils.copyStringToByteArray(panlOnTime, panlOnTime.length, this.DispStrTm);
		byteBuffer.put(panlOnTime);

		byte[] panlOffTime = new byte[4];
		SysUtils.copyStringToByteArray(panlOffTime, panlOffTime.length, this.DispEndTm);
		byteBuffer.put(panlOffTime);

		return byteBuffer;

	}

}
