package com.ywt.core;

import java.io.Serializable;

/**
 * Created by dyh2020
 */
public class BaseResponse implements Serializable {
    public static final int SUCCEED = 0;//成功
    /**
     * 参数错误
     */
    public static final int PARAMETER_ERROR = 1;//参数错误
    /**
     * 应用级别错误
     */
    public static final int APP_ERROR = 2;//应用级别错误
    /**
     * 应用级别异常
     */
    public static final int APP_EXCEPTION = 3;//应用级别异常
    /**
     * 不合法的权限
     */
    public static final int NO_RIGHT = 4;//不合法的权限
    /**
     * 其他错误
     */
    public static final int OTHER_ERROR = 5;//其他错误

    int code;
    String info;

    public BaseResponse succeed(){
        this.code = BaseResponse.SUCCEED;
        this.info = "处理成功";
        return this;
    }

    public BaseResponse succeed(String info){
        this.code = BaseResponse.SUCCEED;
        this.info = info;
        return this;
    }


    public BaseResponse failed(int code){
        this.code = code;
        return this;
    }

    public BaseResponse failed(int code, String info){
        this.code = code;
        this.info = info;
        return this;
    }


    public int getCode() {
        return code;
    }

    public BaseResponse setCode(int code) {
        this.code = code;
        return this;
    }

    public String getInfo() {
        return info;
    }

    public BaseResponse setInfo(String info) {
        this.info = info;
        return this;
    }

    public BaseResponse failedWithParameterError(){
        this.code = BaseResponse.PARAMETER_ERROR;
        this.info = "参数错误";
        return this;
    }

    public BaseResponse failedWithParameterError(String info){
        this.code = BaseResponse.PARAMETER_ERROR;
        this.info = info;
        return this;
    }

    public BaseResponse failedWithAppError(){
        this.code = BaseResponse.APP_ERROR;
        this.info = "处理失败";
        return this;
    }

    public BaseResponse failedWithAppError(String info){
        this.code = BaseResponse.APP_ERROR;
        this.info = info;
        return this;
    }
    public BaseResponse error() {
        this.code = BaseResponse.APP_EXCEPTION;
        this.info = "系统开小差，请稍后重试";
        return this;
    }

    public BaseResponse error(String info) {
        this.code = BaseResponse.APP_EXCEPTION;
        this.info = info;
        return this;
    }


}
