package com.ruoyi.common.tools.result;

import lombok.Data;

import java.io.Serializable;

/**
 * 响应结果实体
 *
 * @author zm
 * @data 2024-04-09
 */
@Data
public class Result implements Serializable {
    /**
     * 返回码
     */
    private Integer code;

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

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

    public Result() {
    }

    //自定义错误代码和错误信息
    public Result(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    //根据枚举固定错误代码获取
    public Result(ResultCode resultCode, Object data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
    }

    /***
     *
     * @description: 操作成功不返回数据
     * @Date: 2020/11/4 16:36
     * @return: com.currency.server.entity.response.Result
     **/
    public static Result success() {
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMsg(ResultCode.SUCCESS.getMsg());
        return result;
    }

    /***
     *
     * @description: 操作成功 返回请求数据
     * @Date: 2020/11/4 16:36
     * @return: com.currency.server.entity.response.Result
     **/
    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMsg(ResultCode.SUCCESS.getMsg());
        result.setData(data);
        return result;

    }

    /***
     *
     * @description: 操作失败 返回请求数据
     * @Date: 2020/11/4 16:36
     * @return: com.currency.server.entity.response.Result
     **/
    public static Result failure(ResultCode resultCode) {
        Result result = new Result();
        result.setCode(resultCode.getCode());
        result.setMsg(resultCode.getMsg());
        return result;

    }

    /***
     *
     * @description: 操作失败 返回请求数据
     * @Date: 2020/11/4 16:36
     * @return: com.currency.server.entity.response.Result
     **/
    public static Result error(String message) {
        Result result = new Result();
        result.setCode(500);
        result.setMsg(message);
        return result;
    }

    /***
     *
     * @description: 操作失败 返回请求数据
     * @Date: 2020/11/4 16:36
     * @return: com.currency.server.entity.response.Result
     **/
    public static Result failure(Integer code, String message) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(message);
        return result;

    }

    /***
     *
     * @description: 操作成功 返回请求数据
     * @Date: 2020/11/4 16:36
     * @return: com.currency.server.entity.response.Result
     **/
    public static Result failure(ResultCode resultCode, Object data) {
        Result result = new Result();
        result.setCode(resultCode.getCode());
        result.setMsg(resultCode.getMsg());
        result.setData(data);
        return result;

    }

    /***
     *
     * @description: 自定义返回码和返回信息
     * @Date: 2020/11/4 16:36
     * @return: com.currency.server.entity.response.Result
     **/
    public static Result custom(Integer code, String message, Object data) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(message);
        result.setData(data);
        return result;
    }
}
