package com.happy.Until;

import com.happy.constant.ResultStatusCode;

/**
 * @author yp
 * @date 2019/10/31 0:02
 */
public class ResultUtil {
    private static final long serialVersionUID = 1L;
    // 响应状态
    protected Integer status = 0;

    // 响应消息
    protected String msg;

    // 响应数据
    protected Object data;

    public static ResultUtil buildOK() {
        return new ResultUtil(ResultStatusCode.OK);
    }

    public static ResultUtil buildOK(Object data) {
        return ResultUtil.build(ResultStatusCode.OK, data);
    }

    public static ResultUtil build(ResultStatusCode rsc) {
        return new ResultUtil(rsc.getStatus(), rsc.getMsg(), null);
    }

    public static ResultUtil build(ResultStatusCode rsc, Object data) {
        return new ResultUtil(rsc.getStatus(), rsc.getMsg(), data);
    }

    public static ResultUtil build(Integer status, String msg, Object data) {
        return new ResultUtil(status, msg, data);
    }

    public static ResultUtil ok(Object data) {
        return new ResultUtil(data);
    }

    public static ResultUtil ok() {
        return new ResultUtil(null);
    }

    public ResultUtil() {

    }

    public static ResultUtil build(Integer status, String msg) {
        return new ResultUtil(status, msg, null);
    }

    public ResultUtil(Integer status, String msg, Object data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public ResultUtil(Object data) {
        this.status = 200;
        this.msg = "OK";
        this.data = data;
    }

    public Boolean isOK() {
        if (null == this.status) {
            return false;
        }
        return this.status == 200;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

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

    @Override
    public String toString() {
        return "ResultUtil [status=" + status + ", msg=" + msg + ", data=" + data + "]";
    }
}
