import type { PermissionKey } from "./catalog";

export * from "./catalog";

/** Prüft, ob ein Berechtigungs-Set einen bestimmten Schlüssel enthält. */
export function hasPermission(
  permissions: readonly string[] | undefined | null,
  key: PermissionKey,
): boolean {
  if (!permissions) return false;
  return permissions.includes(key);
}

/** Mindestens eine der Berechtigungen vorhanden? */
export function hasAnyPermission(
  permissions: readonly string[] | undefined | null,
  keys: PermissionKey[],
): boolean {
  if (!permissions) return false;
  return keys.some((k) => permissions.includes(k));
}

/** Alle Berechtigungen vorhanden? */
export function hasAllPermissions(
  permissions: readonly string[] | undefined | null,
  keys: PermissionKey[],
): boolean {
  if (!permissions) return false;
  return keys.every((k) => permissions.includes(k));
}
