package top.awin_x.learn.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 这是统一的响应格式类，所有的响应都应该是这个类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {
    private boolean success = true;
    private String msg = "success";
    private int count = 0;
    private Object data = "";

    public static Result success(Object data, String msg) {
        Result result = success(data);
        result.setMsg(msg);
        return result;
    }

    public static Result success(Object data) {
        Result result = new Result();
        result.setSuccess(true);
        result.setData(data);
        return result;
    }

    public static Result success() {
        return success("");
    }

    public static Result success(boolean isSuccess) {
        Result result = new Result();
        result.setSuccess(isSuccess);
        if (isSuccess){
            result.setMsg("success");
        }else{
            result.setMsg("fail");
        }
        return result;
    }

    public static Result error(String msg) {
        Result result = new Result();
        result.setSuccess(false);
        result.setMsg(msg);
        return result;
    }

    public static Result error(Object data, String msg) {
        Result result = error(msg);
        result.setData(data);
        return result;
    }
}
