package tech.easyflow.system.enums;

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

public enum VisibilityScope {

    PRIVATE,
    DEPT,
    PUBLIC;

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

    public static VisibilityScope fromOrDefault(String code, VisibilityScope defaultValue) {
        if (code == null || code.isBlank()) {
            return defaultValue;
        }
        return from(code);
    }
}
