package com.mortals.xhx.module.api.feign.portal;

public enum ApiResponseCode {
    FAILURE(-1, "failure"),
    SUCCESS(1, "success"),
    PARAM_ERROR(400, "参数错误"),
    UNAUTHORIZED(401, "会话认证失败"),
    LOGIN_ERROR(402, "登录失败"),
    NO_RIGHT(403, "没有权限"),
    SOURCE_NOT_FOUND(404, "未找到数据"),
    USER_DISABLE(405, "用户禁用"),
    STATUS_ERROR(412, "数据状态不允许本次操作"),
    FILE_FAIL_ERROR(413, "不支持的文件格式"),


    UNKNOWN_ERROR(500, "未知错误");

    private int code;

    private String desc;

    public void throwError() {
        BusinesException.throwError(this);
    }

    public void throwError(String msg) {
        BusinesException.throwError(this.code, msg);
    }

	public void assertTrue (boolean condition) {
        if (!condition) {
            throwError();
        }
	}
    public void assertTrue (boolean condition, String msg) {
        if (!condition) {
            throwError(msg);
        }
    }

	public void throwError(Object data) {
		BusinesException.throwError(this, data);
	}
	
	ApiResponseCode(int code, String desc) {
		this.code = code;
		this.desc = desc;
	}

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

}
