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

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.pwt.netty.common.chargerold.RequestData;
import io.netty.buffer.ByteBuf;
import lombok.Data;

import java.nio.charset.StandardCharsets;

/***
 * @author linyun
 * @version V1.0
 * @Title: BatteryOtherData
 * @Description: 电池其他数据包
 * @date 2022/11/15
 **/
@Data
public class BatteryOtherData extends RequestData {

    /**电池编码长度*/
    @JsonIgnore
    private final int BATTERY_CODE_LENGTH = 8;

    /**累计放电电量*/
    private int status1;

    /**累计放电电量*/
    private int status2;

    /**单次充电电量(充电机在线时)*/
    private short status3;

    /**BMS允许的脉冲放电电流（瞬时电流）*/
    private short status4;

    /**BMS允许的脉冲回充电流（瞬时电流）*/
    private short status5;

    /**BMS允许的持续回充电流（燃料电池或 PHEV才有)*/
    private short status6;

    /**BMS允许的持续放电电流（V2V或者储能才有）*/
    private short status7;

    /**充电继电器请求（若该项目为多合一项目，且该项目存在该继电器）*/
    private byte status8;

    /**加热正继电器请求（若该项目为多合一项目，且该项目存在该继电器）*/
    private byte status9;

    /**加热负继电器请求（若该项目为多合一项目，且该项目存在该继电器）*/
    private byte status10;

    /**加热负继电器请求（若该项目为多合一项目，且该项目存在该继电器）*/
    private byte status11;

    /**主负继电器请求（若该项目为多合一项目，且该项目存在该继电器）*/
    private byte status12;

    /**绝缘禁止请求（多合一项目）*/
    private byte status13;

    /**主负继电器线圈状态（多合一项目）*/
    private byte status14;

    /**备用*/
    private byte reserved1;

    /**备用*/
    private byte reserved2;

    /**电池箱号（探测器编号，轮询发送）*/
    private byte status15;

    /**探测器启动灭火弹类型*/
    private byte status16;

    /**火情级别*/
    private byte status17;

    /**故障码*/
    private byte status18;

    /**子阀打开或关闭命令*/
    private byte status19;

    /**灭火系统故障码*/
    private byte status20;

    /**预留*/
    private byte reserved3;

    /**报文RollingCounter*/
    private byte status21;

    /**电池资产归属公司编码*/
    private String status22;

    /**电池运营公司编码*/
    private String status23;

    /**累计馈电电量*/
    private int status24;

    /**本帧起始支路序号（从1开始）*/
    private byte status25;

    /**Current ofNo.1 Branchin this frame(Send0xFFFF ifthe voltagevalue isinvail)*/
    private short status26;

    /**Current ofNo.2 Branchin this frame(Send0xFFFF ifthe voltagevalue isinvail)*/
    private short status27;

    /**备用*/
    private byte reserved4;
    
    /**备用*/
    private byte reserved5;

    /***
     * 子类编码
     * @param byteBuf
     */
    @Override
    protected void encodeInternal(ByteBuf byteBuf)
    {
        byteBuf.writeInt(getStatus1());
        byteBuf.writeInt(getStatus2());
        byteBuf.writeShort(getStatus3());
        byteBuf.writeShort(getStatus4());
        byteBuf.writeShort(getStatus5());
        byteBuf.writeShort(getStatus6());
        byteBuf.writeShort(getStatus7());
        byteBuf.writeByte(getStatus8());
        byteBuf.writeByte(getStatus9());
        byteBuf.writeByte(getStatus10());
        byteBuf.writeByte(getStatus11());
        byteBuf.writeByte(getStatus12());
        byteBuf.writeByte(getStatus13());
        byteBuf.writeByte(getStatus14());
        byteBuf.writeByte(getReserved1());
        byteBuf.writeByte(getReserved2());
        byteBuf.writeByte(getStatus15());
        byteBuf.writeByte(getStatus16());
        byteBuf.writeByte(getStatus17());
        byteBuf.writeByte(getStatus18());
        byteBuf.writeByte(getStatus19());
        byteBuf.writeByte(getStatus20());
        byteBuf.writeByte(getReserved3());
        byteBuf.writeByte(getStatus21());
        byteBuf.writeBytes(getStatus22().getBytes(StandardCharsets.US_ASCII));
        byteBuf.writeBytes(getStatus23().getBytes(StandardCharsets.US_ASCII));
        byteBuf.writeInt(getStatus24());
        byteBuf.writeByte(getStatus25());
        byteBuf.writeShort(getStatus26());
        byteBuf.writeShort(getStatus27());
        byteBuf.writeByte(getReserved4());
        byteBuf.writeByte(getReserved5());
    }

    /**
     * 子类解码
     *
     * @param byteBuf
     */
    @Override
    protected void decodeInternal(ByteBuf byteBuf)
    {
        setStatus1(byteBuf.readInt());
        setStatus2(byteBuf.readInt());
        setStatus3(byteBuf.readShort());
        setStatus4(byteBuf.readShort());
        setStatus5(byteBuf.readShort());
        setStatus6(byteBuf.readShort());
        setStatus7(byteBuf.readShort());
        setStatus8(byteBuf.readByte());
        setStatus9(byteBuf.readByte());
        setStatus10(byteBuf.readByte());
        setStatus11(byteBuf.readByte());
        setStatus12(byteBuf.readByte());
        setStatus13(byteBuf.readByte());
        setStatus14(byteBuf.readByte());
        setReserved1(byteBuf.readByte());
        setStatus15(byteBuf.readByte());
        setStatus16(byteBuf.readByte());
        setStatus17(byteBuf.readByte());
        setStatus18(byteBuf.readByte());
        setStatus19(byteBuf.readByte());
        setStatus20(byteBuf.readByte());
        setReserved2(byteBuf.readByte());
        setReserved3(byteBuf.readByte());
        setStatus21(byteBuf.readByte());
        setStatus22(byteBuf.readCharSequence(BATTERY_CODE_LENGTH, StandardCharsets.US_ASCII).toString());
        setStatus23(byteBuf.readCharSequence(BATTERY_CODE_LENGTH, StandardCharsets.US_ASCII).toString());
        setStatus24(byteBuf.readInt());
        setStatus25(byteBuf.readByte());
        setStatus26(byteBuf.readShort());
        setStatus27(byteBuf.readShort());
        setReserved4(byteBuf.readByte());
        setReserved5(byteBuf.readByte());
    }
}
