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

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

/**
 * @author linyun
 * @version V1.0
 * @Title: SetParametersData
 * @Description: 设置参数
 * @date 2022/11/15
 **/
@Data
@EqualsAndHashCode
public class SetParametersData extends RequestData {

    /**电量比例*/
    private double vehicleTotalDischargeRation = 0.01;

    /** 车辆累计放电量 */
    private double vehicleTotalDischarge;

    /**车辆累计回馈电量*/
    private double vehicleTotalFeedBackCharge;

    /**车辆累计充电量*/
    private double vehicleTotalAmountCharge;

    /**车辆累计综合能耗*/
    private double vehicleTotalComprehensiveEnergy;

    /**本次实时放电量*/
    private double vehicleDischarge;

    /**上次结算放电量*/
    private double lastCountDischarge;

    /**本次回馈放电量*/
    private double feedbackDischarge;

    /**上一次结算回馈电量*/
    private double lastSettlementFeedbackPower;

    /**本次插枪充电量*/
    private double amountCharge;

    /**上一次结算插枪电量*/
    private double lastSettlementAmountCharge;

    /**本次实时综合能耗*/
    private double comprehensiveEnergy;

    /**上一次结算综合能耗*/
    private double lastSettlementComprehensiveEnergy;

    /***
     * 子类编码
     * @param byteBuf
     */
    @Override
    protected void encodeInternal(ByteBuf byteBuf)
    {
        int value1 = (int) (vehicleTotalDischarge / vehicleTotalDischargeRation);
        int value2 = (int) (vehicleTotalFeedBackCharge / vehicleTotalDischargeRation);
        int value3 = (int) (vehicleTotalAmountCharge / vehicleTotalDischargeRation);
        int value4 = (int) (vehicleTotalComprehensiveEnergy / vehicleTotalDischargeRation);
        int value5 = (int) (vehicleDischarge / vehicleTotalDischargeRation);
        int value6 = (int) (lastCountDischarge / vehicleTotalDischargeRation);
        int value7 = (int) (feedbackDischarge / vehicleTotalDischargeRation);
        int value8 = (int) (lastSettlementFeedbackPower / vehicleTotalDischargeRation);
        int value9 = (int) (amountCharge / vehicleTotalDischargeRation);
        int value10 = (int) (lastSettlementAmountCharge / vehicleTotalDischargeRation);
        int value11 = (int) (comprehensiveEnergy / vehicleTotalDischargeRation);
        int value12 = (int) (lastSettlementComprehensiveEnergy / vehicleTotalDischargeRation);

        byteBuf.writeMediumLE(value1);
        byteBuf.writeMediumLE(value2);
        byteBuf.writeMediumLE(value3);
        byteBuf.writeMediumLE(value4);
        byteBuf.writeMediumLE(value5);
        byteBuf.writeMediumLE(value6);
        byteBuf.writeMediumLE(value7);
        byteBuf.writeMediumLE(value8);
        byteBuf.writeMediumLE(value9);
        byteBuf.writeMediumLE(value10);
        byteBuf.writeMediumLE(value11);
        byteBuf.writeMediumLE(value12);
    }

    /**
     * 子类解码
     *
     * @param byteBuf
     */
    @Override
    protected void decodeInternal(ByteBuf byteBuf)
    {
        int value1 = byteBuf.readMediumLE();
        int value2 = byteBuf.readMediumLE();
        int value3 = byteBuf.readMediumLE();
        int value4 = byteBuf.readMediumLE();
        int value5 = byteBuf.readMediumLE();
        int value6 = byteBuf.readMediumLE();
        int value7 = byteBuf.readMediumLE();
        int value8 = byteBuf.readMediumLE();
        int value9 = byteBuf.readMediumLE();
        int value10 = byteBuf.readMediumLE();
        int value11 = byteBuf.readMediumLE();
        int value12 = byteBuf.readMediumLE();

        setVehicleTotalDischarge(value1 * vehicleTotalDischargeRation);
        setVehicleTotalFeedBackCharge(value2 * vehicleTotalDischargeRation);
        setVehicleTotalAmountCharge(value3 * vehicleTotalDischargeRation);
        setVehicleTotalComprehensiveEnergy(value4 * vehicleTotalDischargeRation);
        setVehicleDischarge(value5 * vehicleTotalDischargeRation);
        setLastCountDischarge(value6 * vehicleTotalDischargeRation);
        setFeedbackDischarge(value7 * vehicleTotalDischargeRation);
        setLastSettlementFeedbackPower(value8 * vehicleTotalDischargeRation);
        setAmountCharge(value9 * vehicleTotalDischargeRation);
        setLastSettlementAmountCharge(value10 * vehicleTotalDischargeRation);
        setComprehensiveEnergy(value11 * vehicleTotalDischargeRation);
        setLastSettlementComprehensiveEnergy(value12 * vehicleTotalDischargeRation);
    }
}
