package org.springblade.auth.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * 入库类型
 */
@Getter
public enum LoginTypeEnum {

    STORAGE_APPLET("storageApplet"),
    FOREIGN_TRADE_SUPERMAN("foreignTradeSuperman"),
    LOGIN_WITHOUT_VERIFICATION_CODE("loginWithoutVerificationCode"),
    DEFAULT_LOGIN("defaultLogin"),
    ;

    private final String type;

    private static final HashMap<String, LoginTypeEnum> map = new HashMap<>();

    LoginTypeEnum(String type) {
        this.type = type;
    }

    static {
        for (LoginTypeEnum value : LoginTypeEnum.values()) {
            map.put(value.getType(), value);
        }
    }

    /**
     * 根据type获取枚举
     */
    public static LoginTypeEnum get(String type) {
        LoginTypeEnum loginTypeEnum = map.get(type);
        return loginTypeEnum == null ? DEFAULT_LOGIN : loginTypeEnum;
    }

    /**
     * 获取无需密码登录类型列表
     */
    public static List<LoginTypeEnum> getNoPasswordRequiredTypeList() {
        return Arrays.asList(STORAGE_APPLET, FOREIGN_TRADE_SUPERMAN);
    }

}
