package com.njcn.product.auth.pojo.enums;

import lombok.Getter;

/**
 * @author hongawen
 * @version 1.0.0
 * @date 2021年04月13日 10:50
 */
@Getter
public enum UserResponseEnum {

    /**
     * A0100 ~ A0199 用于用户模块的枚举
     * <p>
     * 大致可以分为：
     * 登录失败状态码 A0101 + 各种登录失败的原因
     * 注册失败状态码 A0103 + 各种注册失败的原因
     * 用户权限升级失败（暂时用于app账号不同角色升级） A0103 + 各种升级app权限失败的原因
     * token校验失败 A0104 + 各种token失败的原因
     * client校验失败 A0105 + 各种客户端失败的原因
     */
    LOGIN_USERNAME_NOT_FOUND("A0101", "用户不存在"),
    LOGIN_USERNAME_INVALID("A0101", "用户名非法"),
    LOGIN_USER_INDEX_INVALID("A0101", "用户索引非法"),
    LOGIN_PHONE_NOT_FOUND("A0101", "手机号不存在"),
    LOGIN_PHONE_NOT_REGISTER("A0101", "手机号未注册"),
    KEY_WRONG("A0101","登录密码/验证码为空"),
    LOGIN_WRONG_PWD("A0101", "用户名密码错误"),
    LOGIN_WRONG_PHONE_CODE("A0101", "短信验证码错误"),
    LOGIN_WRONG_CODE("A0101", "验证码错误"),
    CODE_TYPE_ERROR("A0101","验证码类型非法"),
    SEND_CODE_FAIL("A0101","验证码发送失败"),
    LOGIN_USER_DELETE("A0101", "账号已被注销"),
    LOGIN_USER_OVERLIMIT("A0101", "登陆用户数不能大于配置用户并发量"),
    LOGIN_USER_LOCKED("A0102", "账号已被锁定"),
    LOGIN_USER_UNAUDITED("A0101", "账号未审核"),
    NEED_MODIFY_PASSWORD("A0101", "密码需修改"),
    LOGIN_USER_SLEEP("A0101", "账号已休眠"),
    LOGIN_USER_PASSWORD_EXPIRED("A0101", "账号密码过期"),
    LOGIN_ERROR("A0101", "登录失败"),
    LOGIN_FIRST_LOGIN("A0101", "账号首次登录"),
    NEED_MODIFY_PWD("A0101", "密码失效，请重置"),
    PASSWORD_INVALID("A0101", "密码非法"),
    PASSWORD_SET_ERROR("A0101", "密码设置错误"),
    LACK_USER_STRATEGY("A0101", "缺失用户策略配置"),
    UNSUPPORTED_GRANT_TYPE("A0101", "非法认证方式"),
    INVALID_IP("A0101", "非法IP访问系统"),
    INVALID_TIME("A0101", "用户当前时间段禁止访问"),
    PASSWORD_TRANSPORT_ERROR("A0101", "密码传输完整性被破坏"),
    SPECIAL_PASSWORD("A0101", "密码需要包含特殊字符字母数字，长度为8-16"),
    APP_PASSWORD("A0101", "密码长度为8-16"),
    REPEAT_PASSWORD("A0101", "新密码与旧密码不能一致"),

    MESSAGE_SEND_FAIL("A0102", "短信发送失败"),
    REGISTER_FAIL("A0102", "注册失败"),
    REGISTER_PHONE_FAIL("A0102", "该号码已注册"),
    REGISTER_LOGIN_NAME_FAIL("A0102", "该账号已注册"),
    REGISTER_PHONE_WRONG("A0102", "手机号非法"),
    REGISTER_PHONE_REPEAT("A0102", "手机号已注册"),
    REGISTER_PASSWORD_WRONG("A0102", "账号密码非法"),
    DEV_CODE_WRONG("A0102","设备码非法"),
    REGISTER_LOGIN_NAME_EXIST("A0102", "该登录名已存在,请检查loginName字段"),
    REGISTER_HOMEPAGE_NAME_EXIST("A0102", "该驾驶舱名已存在,请检查name字段"),
    FUNCTION_PATH_EXIST("A0102", "菜单路径已存在,请检查path字段"),
    COMPONENT_NAME_EXIST("A0102", "组件名已存在,请检查name字段"),


    UPDATE_ROLE_REFERRAL_CODE_ERROR("A0103", "推荐码非法"),

    PARSE_TOKEN_FORBIDDEN_JWT("A0104", "token已被禁止访问"),
    REFRESH_TOKEN_EXPIRE_JWT("A0104", "refresh_token已过期"),

    CLIENT_AUTHENTICATION_FAILED("A0105", "客户端认证失败"),
    NOT_FOUND_CLIENT("A0105", "客户端不存在"),

    DEPT_MISSING("A0106", "未找到此部门"),

    DEPT_NODATA("A0107", "部门下暂无用户"),

    BIND_USER_DATA("A0108", "已绑定用户,先解绑用户"),

    CHILD_DEPT_DATA("A0109", "已绑定子部门,先解绑部门"),

    BIND_MONITOR_DATA("A0110", "已绑定监测点,先解绑监测点"),

    BINDING_BUTTON("A0110", "已绑定按钮,先删除按钮"),

    NO_MENU_DATA("A0111","未找到菜单"),

    CHILD_DATA("A0112","数据已绑子节点"),

    BIND_ROLE_DATA("A0113","已有角色绑定，请先解绑"),

    NO_ROLE_DATA("A0114","未找到此角色"),

    BIND_FUNCTION_DATA("A0115","已绑定资源,先解绑资源"),

    DEPT_NAME_REPEAT("A0116","部门名称重复"),

    ROLE_NAME_REPEAT("A0117","角色名称重复"),
    DEPT_PID_EXCEPTION("A0118","新增部门父节点信息异常"),

    REFERRAL_CODE_LAPSE("A0119","角色推荐码失效,请联系管理员"),
    REFERRAL_CODE_ERROR("A0119","角色推荐码错误,请联系管理员"),
    ;

    private final String code;

    private final String message;

    UserResponseEnum(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public static String getCodeByMsg(String msg){
        for (UserResponseEnum userCodeEnum : UserResponseEnum.values()) {
            if (userCodeEnum.message.equalsIgnoreCase(msg)) {
                return userCodeEnum.code;
            }
        }
        return "";
    }
}
