package com.mortals.xhx.busiz.rsp;

import lombok.Data;

@Data
public class ApiResp<T> {

    /**
     * 成功
     */
    public static final String SUCCESS = "1";

    /**
     * 失败
     */
    public static final String FAIL = "-1";
    /**
     * 结果编码
     */
    private String status;
    /**
     * 结果描述
     */
    private String message;
    /**
     * 响应数据
     */
    private T data;


    public static <T> ApiResp<T> ok() {
        return ApiRespResult(null, SUCCESS, "操作成功");
    }

    public static <T> ApiResp<T> ok(T data) {
        return ApiRespResult(data, SUCCESS, "操作成功");
    }

    public static <T> ApiResp<T> ok(String msg) {
        return ApiRespResult(null, SUCCESS, msg);
    }

    public static <T> ApiResp<T> ok(String msg, T data) {
        return ApiRespResult(data, SUCCESS, msg);
    }

    public static <T> ApiResp<T> fail() {
        return ApiRespResult(null, FAIL, "操作失败");
    }

    public static <T> ApiResp<T> fail(String msg) {
        return ApiRespResult(null, FAIL, msg);
    }

    public static <T> ApiResp<T> fail(T data) {
        return ApiRespResult(data, FAIL, "操作失败");
    }

    public static <T> ApiResp<T> fail(String msg, T data) {
        return ApiRespResult(data, FAIL, msg);
    }

    public static <T> ApiResp<T> fail(String code, String msg) {
        return ApiRespResult(null, code, msg);
    }
    private static <T> ApiResp<T> ApiRespResult(T data, String code, String msg) {
        ApiResp<T> ApiResp = new ApiResp<>();
        ApiResp.setStatus(code);
        ApiResp.setData(data);
        ApiResp.setMessage(msg);
        return ApiResp;
    }

}
