package com.ywt.model;

import java.io.Serializable;

/**
 * @author Created by huangguoping.
 */
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;

    private int code;
    private 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 parameterErrorFailed(){
        this.code = BaseResponse.PARAMETER_ERROR;
        this.info = "参数有误";
        return this;
    }

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

    public BaseResponse otherErrorFailed(){
        this.code = BaseResponse.OTHER_ERROR;
        this.info = "数据处理失败";
        return this;
    }

    public BaseResponse otherErrorFailed(String info){
        this.code = BaseResponse.OTHER_ERROR;
        this.info = info;
        return this;
    }

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

    public BaseResponse appExceptionFailed(){
        this.code = BaseResponse.APP_EXCEPTION;
        this.info = "数据处理失败";
        return this;
    }
}
