export const SUPERADMIN_PERMISSIONS = {
  OVERVIEW_READ: "overview.read",
  ANALYTICS_READ: "analytics.read",
  USERS_READ: "users.read",
  USERS_MANAGE: "users.manage",
  CONTENT_MODERATE: "content.moderate",
  MARKETPLACE_MANAGE: "marketplace.manage",
  NOTIFICATIONS_READ: "notifications.read",
  AUDIT_READ: "audit.read",
  SETTINGS_READ: "settings.read",
  SETTINGS_WRITE: "settings.write",
  SESSIONS_MANAGE: "sessions.manage",
  OPS_READ: "ops.read",
  CASES_MANAGE: "cases.manage",
} as const;

export type PermissionMatchMode = "all" | "any";

export function hasPermission(permissions: string[] | undefined, permission: string) {
  return (permissions ?? []).includes(permission);
}

export function matchesPermissions(
  permissions: string[] | undefined,
  requiredPermissions: readonly string[],
  mode: PermissionMatchMode = "all",
) {
  if (!requiredPermissions.length) {
    return true;
  }

  if (mode === "any") {
    return requiredPermissions.some((permission) => hasPermission(permissions, permission));
  }

  return requiredPermissions.every((permission) => hasPermission(permissions, permission));
}
