package com.ywt.alipaympapi.models;

//import io.swagger.annotations.ApiModel;
//import io.swagger.annotations.ApiModelProperty;

/**
 * @author Walker
 * Created on 2019/11/14
 */
//@ApiModel(value = "请求基本响应体")
public class BaseResponse2<T> {
    public static final int SUCCEED = 0;//成功
    /**
     * 参数错误
     */
    public static final int PARAMETER_ERROR = 1;//参数错误
    /**
     * 签名错误
     */
    public static final int SIGN_EEROR = 2;//签名错误
    /**
     * 应用级别错误
     */
    public static final int APP_ERROR = 3;//应用级别错误
    /**
     * 应用级别异常
     */
    public static final int APP_EXCEPTION = 4;//应用级别异常
    /**
     * 其他错误
     */
    public static final int OTHER_ERROR = 5;//其他错误

    /**
     * 不合法的权限
     */
    public static final int NO_RIGHT = 6;//不合法的权限

    /**
     * 未登录
     */
    public static final int NOT_LOGGED_IN = 7;

    /**
     * 支付金额错误
     */
    public static final int PAYMENT_AMOUNT_ERROR = 8;

    /**
     * 对象不存在
     */
    public static final int OBJECT_IS_NOT_EXISTS = 9;

    //@ApiModelProperty(value = "状态码", required = true)
    private int code;
    //@ApiModelProperty(value = "状态信息")
    private String info = "";
    //@ApiModelProperty(value = "数据体")
    private T data;

    public int getCode() {
        return code;
    }

    public BaseResponse2<T> setCode(int code) {
        this.code = code;
        return this;
    }

    public String getInfo() {
        return info;
    }

    public BaseResponse2<T> setInfo(String info) {
        this.info = info;
        return this;
    }

    public T getData() {
        return data;
    }

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

    public BaseResponse2<T> succeed() {
        this.code = BaseResponse2.SUCCEED;
        this.info = "处理成功";
        return this;
    }

    public BaseResponse2<T> succeed(String info) {
        this.code = BaseResponse2.SUCCEED;
        this.info = info;
        return this;
    }

    public BaseResponse2<T> succeed(T data) {
        this.code = BaseResponse2.SUCCEED;
        this.info = "处理成功";
        this.data = data;
        return this;
    }

    public BaseResponse2<T> succeed(String info, T data) {
        this.code = BaseResponse2.SUCCEED;
        this.info = info;
        this.data = data;
        return this;
    }

    public BaseResponse2<T> failed(int code) {
        this.code = code;
        return this;
    }

    public BaseResponse2<T> failed(int code, String info) {
        this.code = code;
        this.info = info;
        return this;
    }

    public BaseResponse2<T> failed(int code, String info, T data) {
        this.code = code;
        this.info = info;
        this.data = data;
        return this;
    }

    public BaseResponse2<T> failedWithParameterError(){
        this.code = BaseResponse2.PARAMETER_ERROR;
        this.info = "参数错误";
        return this;
    }

    public BaseResponse2<T> failedWithParameterError(String info){
        this.code = BaseResponse2.PARAMETER_ERROR;
        this.info = info;
        return this;
    }

    public BaseResponse2<T> failedWithAppError(){
        this.code = BaseResponse2.APP_ERROR;
        this.info = "应用错误";
        return this;
    }

    public BaseResponse2<T> failedWithAppError(String info){
        this.code = BaseResponse2.APP_ERROR;
        this.info = info;
        return this;
    }

    public BaseResponse2<T> error() {
        this.code = BaseResponse2.APP_EXCEPTION;
        this.info = "服务出错，请稍后重试";
        return this;
    }

    public BaseResponse2<T> error(String info) {
        this.code = BaseResponse2.APP_EXCEPTION;
        this.info = info;
        return this;
    }

}
