package org.jeecg.api.wxUtils;

import lombok.Data;

/**
 * 返回参数封装类
 *
 * @param <T>
 * @author songfayuan
 */

@Data
public class Response<T> {
    /**
     * 状态码
     */
    protected int code;

    /**
     * 提示信息
     */
    protected String msg;

    /**
     * 数据
     */
    protected T data;

    /**
     * 成功时状态码
     */
    private static final int SUCCESS_CODE = 200;

    /**
     * 成功时提示信息
     */
    private static final String SUCCESS_MSG = "success";

    /**
     * 异常、错误信息状态码
     */
    private static final int ERROR_CODE = 500;

    /**
     * 异常、错误提示信息
     */
    private static final String ERROR_MSG = "服务器内部异常，请联系技术人员！";

    /**
     * 返回成功消息
     *
     * @param <T>
     * @return
     */
    public static <T> Response<T> success() {
        Response resp = new Response();
        resp.code = (SUCCESS_CODE);
        resp.msg = (SUCCESS_MSG);
        return resp;
    }

    /**
     * 返回成功消息
     *
     * @param <T>
     * @param msg
     * @return
     */
    public static <T> Response<T> successResponse(String msg) {
        Response resp = new Response();
        resp.code = SUCCESS_CODE;
        resp.msg = msg;
        return resp;
    }

    /**
     * 返回错误消息
     *
     * @param <T>
     * @return
     */
    public static <T> Response<T> error() {
        Response resp = new Response();
        resp.code = (ERROR_CODE);
        resp.msg = (ERROR_MSG);
        return resp;
    }

    /**
     * 返回错误消息
     *
     * @param <T>
     * @param msg
     * @return
     */
    public static <T> Response<T> errorResponse(String msg) {
        Response resp = new Response();
        resp.code = ERROR_CODE;
        resp.msg = msg;
        return resp;
    }

    /**
     * 自定义状态码、提示信息
     *
     * @param <T>
     * @param code 状态码
     * @param msg  提示信息
     * @return
     */
    public static <T> Response<T> response(int code, String msg) {
        Response resp = new Response();
        resp.code = (code);
        resp.msg = (msg);
        return resp;
    }

    /**
     * 自定义状态码、提示信息、业务数据
     *
     * @param <T>
     * @param code 状态码
     * @param msg  提示信息
     * @param data 业务数据
     * @return
     */
    public static <T> Response<T> response(int code, String msg, T data) {
        Response<T> resp = new Response<>();
        resp.code = (code);
        resp.msg = (msg);
        resp.data = data;
        return resp;
    }

    /**
     * 返回成功数据
     *
     * @param <T>
     * @param data 业务数据
     * @return
     */
    public static <T> Response<T> success(T data) {
        Response<T> resp = new Response<>();
        resp.code = (SUCCESS_CODE);
        resp.msg = (SUCCESS_MSG);
        resp.data = data;
        return resp;
    }

    /**
     * 返回错误消息
     *
     * @param <T>
     * @param data 业务数据
     * @return
     */
    public static <T> Response<T> error(T data) {
        Response<T> resp = new Response<>();
        resp.code = (ERROR_CODE);
        resp.msg = (ERROR_MSG);
        resp.data = data;
        return resp;
    }
}
