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

import com.pwt.netty.common.vehicle1.Vehicle1Message;
import com.pwt.netty.util.ByteBufUtil;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import java.nio.charset.StandardCharsets;


@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
public class BatterySwapDoneResponse extends Vehicle1Message {

    private String vin;
    private byte vehicleStatus;
    private byte batteryLockStatus;

    public BatterySwapDoneResponse() {
        super((byte)0x23);
    }

    @Override
    public void encode(ByteBuf byteBuf) throws Exception {
        // 1 byte
        byteBuf.writeByte(type);
        // 17 bytes
        ByteBufUtil.WriteString(byteBuf, vin, VIN_LENGTH, "0");
        // 1byte
        byteBuf.writeByte(vehicleStatus);
        // 1byte
        byteBuf.writeByte(batteryLockStatus);
    }

    @Override
    public void decode(ByteBuf byteBuf) throws Exception {
        this.vin = byteBuf.readCharSequence(VIN_LENGTH, StandardCharsets.US_ASCII).toString();
        this.vehicleStatus = byteBuf.readByte();
        this.batteryLockStatus = byteBuf.readByte();
    }

    @Override
    public int getProtocolLength() {
        return 0x14; //20
    }
}
