package com.njzscloud.common.localizer.jt808.message;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
public class ServerRegisterResponseMessage implements ServerMessageBody {
    private String terminalId;
    private int flowId;
    private int result;
    private String authCode;

    @Override
    public byte[] toBytes() {
        ByteBuf body = Unpooled.buffer();
        try {
            body.writeShort(flowId);
            body.writeByte(result);
            ByteBufUtil.writeUtf8(body, authCode);
            return ByteBufUtil.getBytes(body);
        } finally {
            body.release();
        }
    }
}
