package com.pwt.netty.common.charger.server;

import com.pwt.netty.common.charger.RequestData;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 启停命令
 */

@Getter
@Setter
@ToString
@EqualsAndHashCode(callSuper = true)
public class StartStopCommand extends RequestData {

    /*启停性质*/
    private int commandType;

    /*启动条件*/
    private int startCondition;

    /*预约小时*/
    private int appointmentHour;

    /*预约分钟*/
    private int appointmentMinute;

    /*充电方式*/
    private int chargeMode;

    /*充电数据*/
    private int chargeData;

    /*充电电流*/
    private int chargeCurrent;

    /**
     * 充电模式 1：室内充电 2：应急充电
     */
    private int chargeType;


    @Override
    public void encode(ByteBuf byteBuf) {
        byteBuf.writeByte(this.commandType);
        byteBuf.writeByte(this.startCondition);
        byteBuf.writeByte(this.appointmentHour);
        byteBuf.writeByte(this.appointmentMinute);
        byteBuf.writeByte(this.chargeMode);
        byteBuf.writeShort(chargeData);
        byteBuf.writeByte(this.chargeCurrent);
        byteBuf.writeByte(this.chargeType);
        byteBuf.writeByte(this.getEnd());
    }


    @Override
    public void decode(ByteBuf byteBuf) {
        this.commandType = byteBuf.readUnsignedByte();
        this.startCondition = byteBuf.readUnsignedByte();
        this.appointmentHour = byteBuf.readUnsignedByte();
        this.appointmentMinute = byteBuf.readUnsignedByte();
        this.chargeMode = byteBuf.readUnsignedByte();
        this.chargeData = byteBuf.readUnsignedShort();
        this.chargeCurrent = byteBuf.readUnsignedByte();
        this.chargeType = byteBuf.readUnsignedByte();
        byteBuf.skipBytes(1);
    }

    @Override
    public int getProtocolLength() {
        return 10;
    }

    @Override
    public byte getEnd() {
        return 0x16;
    }
}
