package com.liangjian.dataplatform.member.entity.response;

import java.io.Serializable;

/**
 * @Author: 黄子奇
 * @Date: 2019/8/27 9:05
 *
 * Web Restful 响应的返回结构
 * code : 0-成功 1-错误
 * msg : 响应的消息
 * data: 响应的数据
 */
public class ResultObject<T> implements Serializable {
    private static final long serialVersionUID = 3704818036553041837L;

    private Integer code;
    private String msg;
    private Boolean success;
    private T data;

    public ResultObject(Integer code, Boolean success, String msg, T data) {
        this.code = code;
        this.success = success;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ResultObject<T> success(String msg, T data) {
        return new ResultObject<>(0,true,msg,data);
    }

    public static <T> ResultObject<T> success(T data) {
        return success("响应成功",data);
    }

    public static <T> ResultObject<T> success() {
        return success(null);
    }

    public static <T> ResultObject<T> error(String msg) {
        return new ResultObject<>(1,false, msg,null);
    }

    public static <T> ResultObject<T> error() {
        return error("未知错误");
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

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

    public T getData() {
        return data;
    }

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

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }
}
