package org.lym.pom.repository.mongo.enums;

import jakarta.annotation.Nonnull;
import org.shoulder.core.dictionary.model.DictionaryItemEnum;
import org.shoulder.core.dictionary.model.DictionaryType;

/**
 * 枚举字典类型 枚举
 * 所有 Dictionary 实现便于统一注册枚举类【工程自己维护，optional】
 *
 * @deprecated
 * @see org.shoulder.web.template.dictionary.spi.DictionaryItemEnumStore
 * @author lym
 */
public enum DictionaryTypeEnum implements DictionaryType {

    //AttitudeType(AttitudeTypeEnum.class, "用户态度类型"),

    ;

    private final Class<? extends Enum<? extends DictionaryItemEnum<?, String>>> enumClass;
    private final String displayName;

    DictionaryTypeEnum(Class<? extends Enum<? extends DictionaryItemEnum<?, String>>> enumClass,
                       String displayName) {
        this.enumClass = enumClass;
        this.displayName = displayName;
    }

    @Nonnull
    public static DictionaryTypeEnum findByClass(@Nonnull Class<?> clazz) {
        for (DictionaryTypeEnum dictionaryTypeEnum : values()) {
            if(dictionaryTypeEnum.getEnumClass() == clazz){
                return dictionaryTypeEnum;
            }
        }
        throw new IllegalArgumentException("not support such class " + clazz);
    }

    @Nonnull
    public static DictionaryTypeEnum findByTypeName(@Nonnull String typeName) {
        for (DictionaryTypeEnum dictionaryTypeEnum : values()) {
            if(dictionaryTypeEnum.getCode().equalsIgnoreCase(typeName)){
                return dictionaryTypeEnum;
            }
        }
        throw new IllegalArgumentException("not support such type " + typeName);
    }

    public Class<? extends Enum<? extends DictionaryItemEnum<?, String>>> getEnumClass() {
        return enumClass;
    }

    @Override
    public String getCode() {
        return enumClass.getSimpleName();
    }

    public String getDisplayName() {
        return displayName;
    }

    @Override
    public Integer getDisplayOrder() {
        return ordinal();
    }

    @Override
    public boolean modifyAble() {
        return false;
    }

}