package com.jsowell.thirdparty.lianlian.common;


import com.jsowell.thirdparty.lianlian.common.enums.ResultCode;

/**
 * 接口返回类
 *
 * @author 联联充电
 */
public class CommonResult<T> {

    /**
     * 状态码
     */
    private long ret;

    /**
     * 响应信息
     */
    private String msg;

    /**
     * 返回数据
     */
    private T data;

    private String sig;

    protected CommonResult() {

    }

    protected CommonResult(long ret, String msg, T data, String sig) {
        this.ret = ret;
        this.msg = msg;
        this.data = data;
        this.sig = sig;
    }

    /**
     * 成功返回结果
     *
     * @param data 获取的数据
     * @param <T>
     * @return
     */
    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMsg(), data, null);
    }

    /**
     * 成功返回结果
     *
     * @param data    获取的数据
     * @param message 提示的信息
     * @param <T>
     * @return
     */
    public static <T> CommonResult<T> success(T data, String message) {
        return new CommonResult<T>(ResultCode.SUCCESS.getCode(), message, data, null);
    }

    public static <T> CommonResult<T> success(Integer ret, String msg, T data, String sig) {
        return new CommonResult<T>(ret, msg, data, sig);
    }

    /**
     * 失败返回结果
     *
     * @param resultCode 错误码
     * @param <T>
     * @return
     */
    public static <T> CommonResult<T> failed(ResultCode resultCode) {
        return new CommonResult<T>(resultCode.getCode(), resultCode.getMsg(), null, null);
    }

    /**
     * 失败返回
     *
     * @param code 错误码
     * @param msg  提示信息
     * @param <T>
     * @return
     */
    public static <T> CommonResult<T> failed(long code, String msg) {
        return new CommonResult<T>(code, msg, null, null);
    }

    /**
     * 失败返回结果
     *
     * @param msg 提示信息
     * @param <T>
     * @return
     */
    public static <T> CommonResult<T> failed(String msg) {
        return failed(ResultCode.ERROR.getCode(), msg);
    }

    /**
     * 失败返回结果
     *
     * @param <T>
     * @return
     */
    public static <T> CommonResult<T> failed() {
        return failed(ResultCode.ERROR);
    }


    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 long getRet() {
        return ret;
    }

    public void setRet(long ret) {
        this.ret = ret;
    }

    public String getSig() {
        return sig;
    }

    public void setSig(String sig) {
        this.sig = sig;
    }
}
