package com.platform.entity;


import lombok.Data;

import java.io.Serializable;

/**
 * 通用返回类
 *
 * @author
 */
@Data
public class Result implements Serializable {
    private static final long serialVersionUID = -1491499610244557029L;
    public static final String SUCCESS_MSG = "操作成功";
    public static Integer CODE_SUCCESS = 200;
    public static Integer CODE_FAILURE = -1;
    public static String[] NOOP = new String[]{};

    /**
     * 处理状态：0: 成功, 1: 失败
     */
    private Integer code;
    /**
     * 消息
     */
    private String error;
    /**
     * 返回数据
     */

    private Object message;

    public Result(){

    }

    public Result(Integer code, String error, Object message) {
        this.code = code;
        this.error = error;
        this.message = message;
    }

    /**
     * 处理成功，并返回数据
     *
     * @param message 数据对象
     * @return data
     */
    public static Result success(Object message) {
        return new Result(CODE_SUCCESS, SUCCESS_MSG, message);
    }
    /**
     * 处理成功
     *
     * @return data
     */
    public static Result success() {
        return new Result(CODE_SUCCESS, SUCCESS_MSG, NOOP);
    }
    /**
     * 处理成功
     *
     * @param error  消息
     * @param message 数据对象
     * @return data
     */
    public static Result success(String error, Object message) {
        return new Result(CODE_SUCCESS, error, message);
    }
    /**
     * 处理失败，并返回数据（一般为错误信息）
     *
     * @param code 错误代码
     * @param error  消息
     * @return data
     */
    public static Result failure(Integer code, String error) {
        return new Result(code, error, NOOP);
    }
    public static Result failure(Integer code, String error,Object message) {
        return new Result(code, error, message);
    }
    /**
     * 处理失败
     *
     * @param error 消息
     * @return data
     */
    public static Result failure(String error) {
        return failure(CODE_FAILURE, error);
    }

    @Override
    public String toString() {
        return "JsonResult [code=" + code + ", error=" + error + ", message="
                + message + "]";
    }
}
