package tech.easyflow.system.enums;

import java.util.Arrays;
import java.util.Locale;

public enum CategoryScopeMode {

    ALL("ALL"),
    CUSTOM("CUSTOM");

    private final String code;

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

    public String getCode() {
        return code;
    }

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