package com.ruoyi.device.websocket.model;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.device.websocket.TsbWebSocketConstants;

import java.io.Serializable;

/**
 * WebSocket 消息体
 *
 * @author lwm
 */
public class TsbWebSocketMessage implements Serializable
{
    private static final long serialVersionUID = 1L;

    /** 页面/功能标识，如 common:tax */
    private String cmdType;

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

    /** 提示信息 */
    private String message;

    /** 业务数据 */
    private JSONObject data;

    public TsbWebSocketMessage()
    {
    }

    public TsbWebSocketMessage(String cmdType, Integer code, String message, JSONObject data)
    {
        this.cmdType = cmdType;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 失败应答
     */
    public static TsbWebSocketMessage fail(String cmdType, String message)
    {
        return new TsbWebSocketMessage(cmdType, TsbWebSocketConstants.FAIL_CODE, message, null);
    }

    /**
     * 成功应答
     */
    public static TsbWebSocketMessage success(String cmdType, String message, JSONObject data)
    {
        return new TsbWebSocketMessage(cmdType, TsbWebSocketConstants.SUCCESS_CODE, message, data);
    }

    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 getMessage()
    {
        return message;
    }

    public void setMessage(String message)
    {
        this.message = message;
    }

    public JSONObject getData()
    {
        return data;
    }

    public void setData(JSONObject data)
    {
        this.data = data;
    }

}
