package com.persagy.adm.steward.basic.model.response;

import com.persagy.adm.steward.basic.constant.CommonConstants;

import java.io.Serializable;


/***
 * @Description: 操作消息提醒
 *
 * @Author: QiaoPengQiang
 * @Date: 2021/12/29
 */
public class BossResponse<T> implements Serializable {

    private static final long serialVersionUID = 1626120430566031974L;

    private int code;

    private String msg;

    private T data;

    public static <T> BossResponse<T> success() {
        return restResult(null, CommonConstants.SUCCESS, null);
    }

    public static <T> BossResponse<T> success(T data) {
        return restResult(data, CommonConstants.SUCCESS, null);
    }

    public static <T> BossResponse<T> success(T data, String msg) {
        return restResult(data, CommonConstants.SUCCESS, msg);
    }

    public static <T> BossResponse<T> error() {
        return restResult(null, CommonConstants.FAIL, "操作失败");
    }

    public static <T> BossResponse<T> error(String msg) {
        return restResult(null, CommonConstants.FAIL, msg);
    }

    public static <T> BossResponse<T> error(T data) {
        return restResult(data, CommonConstants.FAIL, "操作失败");
    }

    public static <T> BossResponse<T> error(T data, String msg) {
        return restResult(data, CommonConstants.FAIL, msg);
    }

    public static <T> BossResponse<T> error(int code, String msg) {
        return restResult(null, code, msg);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int 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;
    }

    private static <T> BossResponse<T> restResult(T data, int code, String msg) {
        BossResponse<T> apiResult = new BossResponse<T>();
        apiResult.setCode(code);
        apiResult.setData(data);
        apiResult.setMsg(msg);
        return apiResult;
    }
}
