package com.shinsoft.sto.model.system;

import java.io.Serializable;

/**
 * 统一响应结果封装类
 */
public class ResultJSON implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 状态码
     */
    private String code;

    /**
     * 消息
     */
    private String msg;

    /**
     * 数据
     */
    private Object data;

    // 构造方法 - 兼容 JSONTools.java 中的使用
    public ResultJSON() {
    }

    public ResultJSON(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResultJSON(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    // 兼容 int 类型 code 的构造方法（JSONTools.java 中使用了 int 参数）
    public ResultJSON(int code, String msg) {
        this.code = String.valueOf(code);
        this.msg = msg;
    }

    public ResultJSON(int code, String msg, Object data) {
        this.code = String.valueOf(code);
        this.msg = msg;
        this.data = data;
    }

    // 成功相关静态方法 - 使用 ResponseCodeMsg 常量
    public static ResultJSON success() {
        return new ResultJSON(ResponseCodeMsg.CODE_SUCCESS, ResponseCodeMsg.MSG_OK);
    }

    public static ResultJSON success(String msg) {
        return new ResultJSON(ResponseCodeMsg.CODE_SUCCESS, msg);
    }

    public static ResultJSON success(Object data) {
        return new ResultJSON(ResponseCodeMsg.CODE_SUCCESS, ResponseCodeMsg.MSG_OK, data);
    }

    public static ResultJSON success(String msg, Object data) {
        return new ResultJSON(ResponseCodeMsg.CODE_SUCCESS, msg, data);
    }

    // 错误相关静态方法
    public static ResultJSON error() {
        return new ResultJSON(ResponseCodeMsg.CODE_FAIL, ResponseCodeMsg.MSG_FAIL);
    }

    public static ResultJSON error(String msg) {
        return new ResultJSON(ResponseCodeMsg.CODE_FAIL, msg);
    }

    public static ResultJSON error(String code, String msg) {
        return new ResultJSON(code, msg);
    }

    public static ResultJSON error(String code, String msg, Object data) {
        return new ResultJSON(code, msg, data);
    }

    // 兼容 int 类型 code 的错误方法
    public static ResultJSON error(int code, String msg) {
        return new ResultJSON(code, msg);
    }

    public static ResultJSON error(int code, String msg, Object data) {
        return new ResultJSON(code, msg, data);
    }

    // Getter 和 Setter 方法
    public String getCode() {
        return code;
    }

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

    public String getMsg() {
        return msg;
    }

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

    public Object getData() {
        return data;
    }

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

    // 判断是否成功的方法
    public boolean isSuccess() {
        return ResponseCodeMsg.CODE_SUCCESS.equals(this.code);
    }

    @Override
    public String toString() {
        return "ResultJSON{" +
                "code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}