package tech.easyflow.system.enums;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

public enum CategoryResourceType {

    BOT("BOT"),
    AGENT("AGENT"),
    SKILL("SKILL"),
    PLUGIN("PLUGIN"),
    WORKFLOW("WORKFLOW"),
    KNOWLEDGE("KNOWLEDGE"),
    RESOURCE("RESOURCE");

    private final String code;

    CategoryResourceType(String code) {
        this.code = code;
    }

    public String getCode() {
        return code;
    }

    public static CategoryResourceType from(String code) {
        if (code == null) {
            throw new IllegalArgumentException("resourceType不能为空");
        }
        String normalized = code.trim().toUpperCase(Locale.ROOT);
        return Arrays.stream(values())
                .filter(item -> item.code.equals(normalized))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("不支持的resourceType: " + code));
    }

    public static List<String> allCodes() {
        return Arrays.stream(values()).map(CategoryResourceType::getCode).collect(Collectors.toList());
    }
}
