package com.ruoyi.device.mqtt.domain;

import com.ruoyi.device.mqtt.constants.MqttConstants;

/**
 * TSB 调试宝统一 JSON Body（firstType=0x4A 时 UTF-8 JSON）
 *
 * @author lwm
 */
public class BaseJsonBody extends BaseBody
{
    /** 请求方法类型，如 tsb:login:up */
    private String cmdType;

    /** 是否成功，1:成功，0:失败 */
    private Integer code;

    /** 正确或者错误提示 */
    private String msg;

    public BaseJsonBody()
    {
        super();
    }

    public BaseJsonBody(String deviceType, Long deviceSn, String cmdType, Integer code, String msg)
    {
        super(deviceType, deviceSn);
        this.cmdType = cmdType;
        this.code = code;
        this.msg = msg;
    }

    /**
     * 失败应答（不指定下行 cmdType）
     */
    public static BaseJsonBody fail(String deviceType, Long deviceSn, String msg)
    {
        return fail(deviceType, deviceSn, null, msg);
    }

    /**
     * 失败应答（可指定下行 cmdType）
     */
    public static BaseJsonBody fail(String deviceType, Long deviceSn, String cmdType, String msg)
    {
        return new BaseJsonBody(deviceType, deviceSn, cmdType, MqttConstants.FAIL_CODE, msg);
    }

    public String getCmdType()
    {
        return cmdType;
    }

    public void setCmdType(String cmdType)
    {
        this.cmdType = cmdType;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
