package test05.pojo;

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

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {
    private boolean success=true;
    private int count=-1;
    @NonNull
    private String msg="success";
    @NonNull
    private Object data="";

    public static Result success(Object data, String msg) {
        return success(data, msg, -1);
    }

    public static Result success(Object data, int count){
        return success(data, "success", count);
    }

    public static Result success(Object data, String msg, int count) {
        Result result = success(data);
        result.setMsg(msg);
        result.setCount(count);
        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("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(String msg, Object data) {
        Result result = error(msg);
        result.setData(data);
        return result;
    }
}
