package com.its.op.xnetudp.protocol;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

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

@Data
@EqualsAndHashCode(callSuper=false)
@ToString
public class CENTER_PG_STATE_RES extends CENTER_COMM_MESSAGE {

	public static int STATE_RES_HEAD_SIZE = 5;
	public static byte STATE_NORMAL = 0x00;
	public static byte STATE_ERROR = 0x01;

	private byte count;
	private byte type;
	private byte db;
	private byte comm;
	private byte action;

	public CENTER_PG_STATE_RES(int senderId, byte db, byte comm, byte action) {

		super(senderId, CENTER_COMM_DEFINE.INT_OP_PG_STATE_RES, 0, (byte)0x00);

		this.count  = 0x01;
		this.type   = (byte)senderId;
		this.db     = db;
		this.comm   = comm;
		this.action = action;
	}

	@Override
	public ByteBuffer getBuffer() {
		int pktSize = STATE_RES_HEAD_SIZE;
		setLength((short)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((short)getLength());

		byteBuffer.put(this.count);
		byteBuffer.put(this.type);
		byteBuffer.put(this.db);
		byteBuffer.put(this.comm);
		byteBuffer.put(this.action);

		return byteBuffer;
	}

}
