
package com.lideeyunji.tool.framework.yunji.enums;


import com.lideeyunji.tool.framework.yunji.utils.FuncBase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * 表单开发-属性类型
 */
public enum DbFormTypeEnum {

    ALL("all", "所有"),
    DICT("dict", "字典"),
    EXPORT("export", "导出"),
    FOREIGNKEY("foreignkey", "外键"),
    WEB("web", "页面"),
    QUERY("query", "查询"),
    SUMMARY("summary", "统计配置"),
    INDEX("index", "索引");

    private final String type;
    private final String name;

    public String getType() {
        return type;
    }

    public String getName() {
        return name;
    }

    DbFormTypeEnum(String type, String name) {
        this.type = type;
        this.name = name;
    }

    public static DbFormTypeEnum getByType(String type) {
        // 使用流来查找匹配的
        Optional<DbFormTypeEnum> matchingEnum = Arrays.stream(DbFormTypeEnum.values())
                .filter(dbFormTypeEnum -> FuncBase.equals(dbFormTypeEnum.getType(), type))
                .findFirst(); // findFirst()会返回第一个匹配的元素，或者如果找不到则返回一个空的Optional
        // 检查是否找到了匹配的枚举项
        if (matchingEnum.isPresent()) {
            return matchingEnum.get();
        }
        return null;
    }

    public static List<DbFormTypeEnum> getAllEnum(){
        return Arrays.asList(DbFormTypeEnum.values());
    }

    public static List<DbFormTypeEnum> getBaseEnum(){
        List<DbFormTypeEnum> typeList = new ArrayList<>();
        typeList.add(DbFormTypeEnum.WEB);
        typeList.add(DbFormTypeEnum.DICT);
        typeList.add(DbFormTypeEnum.QUERY);
        typeList.add(DbFormTypeEnum.EXPORT);
        typeList.add(DbFormTypeEnum.SUMMARY);
        return typeList;
    }

}
