package com.yeechart.dotMatrix.module.DotMatrix.model.bean;


import lombok.Data;
import org.springframework.util.StringUtils;


@Data
/**
 * 封装类
 */
public class ResultBean<T> {
    /**
     * 状态码
     */
    private int code;
    /**
     * 提示
     */
    private String message;
    /**
     * 内容
     */
    private T data;


    public static ResultBean succeed() {
        return succeed(CodeEnum.SUCCESS.getMessage());
    }

    public static ResultBean succeed(Object data) {
        return succeed(CodeEnum.SUCCESS.getMessage(), data);
    }

    public static ResultBean succeed(String message, Object data) {
        ResultBean resultBean = new ResultBean();
        resultBean.setCode(CodeEnum.SUCCESS.getCode());
        resultBean.setMessage(message);
        resultBean.setData(data);
        return resultBean;
    }

    public static ResultBean defeated() {
        return defeated(CodeEnum.FAIL.getCode(), CodeEnum.FAIL.getMessage());
    }

    public static ResultBean defeated(String message) {
        return defeated(CodeEnum.FAIL.getCode(), StringUtils.isEmpty(message) ? CodeEnum.FAIL.getMessage() : message);
    }


    public static ResultBean defeated(int code, String message) {
        return defeated(code, message, null);
    }

    public static ResultBean defeated(int code) {
        CodeEnum codeEnum = CodeEnum.getByCode(code);
        return defeated(codeEnum.getCode(), codeEnum.getMessage(), codeEnum.getName());
    }

    public static ResultBean defeated(int code, String message, Object data) {
        ResultBean resultBean = new ResultBean();
        resultBean.setCode(code);
        resultBean.setMessage(message);
        resultBean.setData(data);
        return resultBean;
    }


}
