package com.lideeyunji.core.framework.config.aspect.enhance.strategy.enums;

import com.lideeyunji.core.framework.config.aspect.enhance.strategy.sql.*;
import com.lideeyunji.tool.framework.yunji.utils.FuncBase;

import java.util.Arrays;
import java.util.Optional;

public enum SqlEnhanceButtonEnums {

    ADD("新增策略","add", new AddEnhanceSqlStrategy()),
    DEL("删除策略","delete", new DelEnhanceSqlStrategy()),
    EDIT("编辑策略","edit", new EditEnhanceSqlStrategy()),
    DETAIL("详情策略","detail", new DetailEnhanceSqlStrategy()),
    LIST("列表策略","list", new ListEnhanceSqlStrategy()),
    PAGE("分页策略","page", new PageEnhanceSqlStrategy()),
    IMPORT("导入策略","import", new ImportEnhanceSqlStrategy()),
    EXPORT("导出策略","export", new ExportEnhanceSqlStrategy()),
    ;

    private final String name;

    private final String code;
    private final EnhanceSqlStrategy strategy;

    SqlEnhanceButtonEnums(String name, String code, EnhanceSqlStrategy strategy) {
        this.name = name;
        this.code = code;
        this.strategy = strategy;
    }

    public String getName() {
        return name;
    }

    public String getCode() {
        return code;
    }

    public EnhanceSqlStrategy getStrategy() {
        return strategy;
    }

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

    }
}
