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

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

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

public enum JavaEnhanceEnums {

    HTTP("HTTP策略","http", new HttpEnhanceJavaStrategy()),
    ONLINE("在线编辑策略","online_edit", new OnlineEnhanceJavaStrategy()),
    SPRING("spring策略","spring", new SpringEnhanceJavaStrategy()),
    CLASS("class策略","class", new ClassEnhanceJavaStrategy()),
    ;

    private final String name;

    private final String code;
    private final EnhanceJavaStrategy strategy;

    JavaEnhanceEnums(String name, String code, EnhanceJavaStrategy strategy) {
        this.name = name;
        this.code = code;
        this.strategy = strategy;
    }

    public String getName() {
        return name;
    }

    public String getCode() {
        return code;
    }

    public EnhanceJavaStrategy getStrategy() {
        return strategy;
    }

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

    }
}
