package com.cameleer.server.core.rbac;

import java.util.Map;
import java.util.Set;
import java.util.UUID;

public final class SystemRole {
    private SystemRole() {}

    public static final UUID AGENT_ID    = UUID.fromString("00000000-0000-0000-0000-000000000001");
    public static final UUID VIEWER_ID   = UUID.fromString("00000000-0000-0000-0000-000000000002");
    public static final UUID OPERATOR_ID = UUID.fromString("00000000-0000-0000-0000-000000000003");
    public static final UUID ADMIN_ID    = UUID.fromString("00000000-0000-0000-0000-000000000004");

    public static final UUID ADMINS_GROUP_ID = UUID.fromString("00000000-0000-0000-0000-000000000010");

    public static final Set<UUID> IDS = Set.of(AGENT_ID, VIEWER_ID, OPERATOR_ID, ADMIN_ID);

    public static final Map<String, UUID> BY_NAME = Map.of(
            "AGENT", AGENT_ID, "VIEWER", VIEWER_ID, "OPERATOR", OPERATOR_ID, "ADMIN", ADMIN_ID);

    public static boolean isSystem(UUID id) { return IDS.contains(id); }

    /**
     * Normalizes an OIDC scope name to a system role name.
     * Strips optional {@code server:} prefix, case-insensitive.
     * E.g. {@code "server:admin"} → {@code "ADMIN"}, {@code "viewer"} → {@code "VIEWER"}.
     */
    public static String normalizeScope(String scope) {
        String upper = scope.toUpperCase();
        return upper.startsWith("SERVER:") ? upper.substring("SERVER:".length()) : upper;
    }
}
