package com.ihooyah.common.msg;

/**
 * @author 王尧 【wangyao@ihooyah.com】
 * @description
 * @create 2018-03-30 下午8:05
 **/
public enum RespEnum {
    //基础请求
    SUCCESS(200, "请求成功"),
    ERROR(500, "请求失败"),
    INVALID_PARAMS(400, ""),
    //授权相关 11000
    AUTH_NO_ACCESS(11001, "没有权限访问该资源"),
    AUTH_ACCESSTOKEN_EXPIRED(11002, "ACCESS_TOKEN已失效"),
    AUTH_ACCESSTOKEN_INEXISTENCE(11003, "ACCESS_TOKEN不存在"),
    //用户相关 12000
    USER_NOLOGIN(12001, "用户未登录"),
    USER_INVALID_PWD(12002, "用户密码错误"),
    USER_INVALID_LOGINNAME(12003, "用户不存在"),

    //公安网证相关 13000
    AUTHENTICATION_ERROR(13002, "查询失败，请重试");

    private int code;
    private String msg;

    private RespEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 通过code获取对应的内容
     *
     * @param
     * @return
     * @author 王尧 【wangyao@ihooyah.com】
     * @date 2018/3/30 下午8:15
     **/
    public static String getMsgByCode(int code) {
        for (RespEnum responseEnum : RespEnum.values()) {
            if (responseEnum.getCode() == code) {
                return responseEnum.msg;
            }
        }
        return null;
    }

    public int getCode() {
        return code;
    }

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

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
