package com.ruixuan.common.core.domain;

/**
 * ***************************************************
 *
 * @Auther: zianY
 * @Descipion: 返回数据统一处理结果
 *       框架自带的处理返回结果 com.ruixuan.common.core.domain.AjaxResult 不支持swagger 显示返回数据结果
 * @CreateDate: 2022-05-19
 * ****************************************************
 */


public class ResultResponse<T> {


    /**
     * 返回状态码
     */
    private final int code;

    /**
     * 返回消息
     */
    private final String msg;

    /**
     * 返回数据
     */
    private final T data;


    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }

    private ResultResponse(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ResultResponse<T> result(int code, String msg, T data) {
        return new ResultResponse<>(code, msg, data);
    }

    public static <T> ResultResponse<T> successMsg(String msg, T data) {
        return new ResultResponse<>(200, msg, data);
    }



    public static <T> ResultResponse<T> success() {
        return success(null);
    }

    public static <T> ResultResponse<T> success(T data) {
        return result(200, Constant.SUCCESS, data);
    }

    public static <T> ResultResponse<T> error(int code, String msg) {
        return error(code, msg, null);
    }

    public static <T> ResultResponse<T> error(int code, String msg, T data) {
        return result(code, msg, data);
    }

    public static <T> ResultResponse<T> error(String msg, T data) {
        return error(5001, msg, data);
    }

    public static <T> ResultResponse<T> error(String msg) {
        return error(msg, null);
    }

    public static <T> ResultResponse<T> error() {
        return error(Constant.ERROR);
    }

    public static class Constant {

        private Constant() {
        }

        public static final String SUCCESS = "success";

        public static final String ERROR = "error";
    }
}
