package com.kcim.common.util;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kcim.common.enums.ResultCodeEnum;

/**
 * 统一封装返回对象
 */
public class Result {

    private static final ObjectMapper MAPPER = new ObjectMapper();
    // 响应业务状态
     private Integer code;

     private Integer status;

    // 响应消息
     private String msg;

    // 响应中的数据
    private Object data;


    @JsonIgnore
    private String ok;	// 不使用

    public static Result build(Integer status, String msg, Object data) {
        return new Result(status, msg, data);
    }
    public static Result build(ResultCodeEnum codeEnum, Object data) {
        Integer code = codeEnum.getCode();
        String msg=codeEnum.getMessage();
        return new Result(code, msg, data);
    }

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


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

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

    }

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

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

    public Result(Object data) {
        this.status = 200;
        this.msg = "success";
        this.data = data;
    }

    public Boolean isOK() {
        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;
    }

    public String getOk() {
        return ok;
    }

    public void setOk(String ok) {
        this.ok = ok;
    }
}
