package com.pwt.netty.common.chargerold.client;

import com.pwt.netty.common.chargerold.RequestData;
import io.netty.buffer.ByteBuf;
import lombok.Data;

/**
 * @author linyun
 * @version V1.0
 * @Title: ChargeCompleteData
 * @Description: 充电完成数据包
 * @date 2022/11/15
 **/
@Data
public class ChargeCompleteData extends RequestData {

    /*充电状态*/
    private byte status;

    /*充电开始时间*/
    private int chargeStartTime;

    /*充电开始时间*/
    private int chargeEndTime;

    /*开始soc*/
    private byte startSoc;

    /*结束soc*/
    private byte endSoc;

    /*充电前电表读数*/
    private float beforeChargeData;

    /*充电前电表读数*/
    private float afterChargeData;

    /*本次充电电量*/
    private float currentChargeData;

    /*最高电池温度*/
    private float highBatteryTemperature;

    /*最低电池温度*/
    private float lowBatteryTemperature;

    /*停止原因*/
    private byte stopReason;

    /***
     * 子类编码
     * @param byteBuf
     */
    @Override
    protected void encodeInternal(ByteBuf byteBuf)
    {
        byteBuf.writeByte(getStatus());
        byteBuf.writeInt(getChargeStartTime());
        byteBuf.writeInt(getChargeEndTime());
        byteBuf.writeByte(getStartSoc());
        byteBuf.writeByte(getEndSoc());
        byteBuf.writeFloat(getBeforeChargeData());
        byteBuf.writeFloat(getAfterChargeData());
        byteBuf.writeFloat(getCurrentChargeData());
        byteBuf.writeFloat(getHighBatteryTemperature());
        byteBuf.writeFloat(getLowBatteryTemperature());
        byteBuf.writeByte(getStopReason());
    }

    /**
     * 子类解码
     *
     * @param byteBuf
     */
    @Override
    protected void decodeInternal(ByteBuf byteBuf)
    {
        setStatus(byteBuf.readByte());
        setChargeStartTime(byteBuf.readInt());
        setChargeEndTime(byteBuf.readInt());
        setStartSoc(byteBuf.readByte());
        setEndSoc(byteBuf.readByte());
        setBeforeChargeData(byteBuf.readFloat());
        setAfterChargeData(byteBuf.readFloat());
        setCurrentChargeData(byteBuf.readFloat());
        setHighBatteryTemperature(byteBuf.readFloat());
        setLowBatteryTemperature(byteBuf.readFloat());
        setStopReason(byteBuf.readByte());
    }
}
