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

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

/**
 * 终端通用响应
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class TerminalGeneralResponseMessage {
    /**
     * 流水号
     */
    private int flowId;
    /**
     * 消息ID
     */
    private int messageId;
    /**
     * 0：成功/确认；1：失败；2：消息有误；3：不支持
     */
    private int result;

    public TerminalGeneralResponseMessage(ByteBuf body) {
        this.flowId = body.readUnsignedShort();
        this.messageId = body.readUnsignedShort();
        this.result = body.readByte();
    }

    public boolean isSuccess() {
        return result == 0;
    }

    public String getMsg() {
        switch (this.result) {
            case 0:
                return "成功";
            case 1:
                return "失败";
            case 2:
                return "消息有误";
            case 3:
                return "不支持";
            default:
                return "未知";
        }
    }
}
