export const ROLE_SUPER_ADMIN = "super_admin";
export const ROLE_TENANT_ADMIN = "tenant_admin";
export const ROLE_RP_ADMIN = "rp_admin";
export const ROLE_USER = "user";

export type AdminRole =
  | typeof ROLE_SUPER_ADMIN
  | typeof ROLE_TENANT_ADMIN
  | typeof ROLE_RP_ADMIN
  | typeof ROLE_USER;

export function normalizeAdminRole(role?: string | null): AdminRole {
  const normalized = role?.trim().toLowerCase() ?? "";

  switch (normalized) {
    case ROLE_SUPER_ADMIN:
    case "superadmin":
    case "super-admin":
      return ROLE_SUPER_ADMIN;
    case ROLE_TENANT_ADMIN:
    case "tenantadmin":
    case "tenant-admin":
    case "admin":
      return ROLE_TENANT_ADMIN;
    case ROLE_RP_ADMIN:
    case "rpadmin":
    case "rp-admin":
      return ROLE_RP_ADMIN;
    case ROLE_USER:
    case "tenant_member":
    case "member":
      return ROLE_USER;
    default:
      return ROLE_USER;
  }
}

export function isSuperAdminRole(role?: string | null) {
  return normalizeAdminRole(role) === ROLE_SUPER_ADMIN;
}
