package com.boman.web.core.domain;

/**
 * @author shiqian
 * @description
 * @date 2021年03月22日 10:59
 **/
public class RowResult {

    private Integer code;
    private String message;
    private Object data;

    public RowResult() {
    }

    public boolean isOk() {
        return this.code >= 0;
    }

    public static RowResult ok(String message) {
        return create(0, message);
    }

    public static RowResult ok(String message, Object data) {
        return create(0, message, data);
    }

    public static RowResult error(String message) {
        return create(-1, message);
    }

    public static RowResult error(String message, Object data) {
        return create(-1, message, data);
    }

    public static RowResult create(Integer errorCode, String message) {
        return create(errorCode, message, (Object)null);
    }

    public static RowResult create(Integer errorCode, String message, Object data) {
        RowResult result = new RowResult();
        result.code = errorCode;
        result.message = message;
        result.data = data;
        return result;
    }

    public Integer getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public Object getData() {
        return this.data;
    }

    public void setData(final Object data) {
        this.data = data;
    }

    public static boolean checkSuccess(RowResult rowResult){
        return null != rowResult && 0 == rowResult.getCode();
    }

    public static boolean checkFail(RowResult rowResult){
        return !checkSuccess(rowResult);
    }
}
