export enum AdminRole {
  SUPER_ADMIN = 'SUPER_ADMIN',
  ADMIN = 'ADMIN',
  OPERATIONS = 'OPERATIONS',
  DEVELOPER = 'DEVELOPER',
  READONLY = 'READONLY',
}

export const ADMIN_ROLE_HIERARCHY: Record<AdminRole, AdminRole[]> = {
  [AdminRole.SUPER_ADMIN]: [
    AdminRole.SUPER_ADMIN,
    AdminRole.ADMIN,
    AdminRole.OPERATIONS,
    AdminRole.DEVELOPER,
    AdminRole.READONLY,
  ],
  [AdminRole.ADMIN]: [
    AdminRole.ADMIN,
    AdminRole.OPERATIONS,
    AdminRole.DEVELOPER,
    AdminRole.READONLY,
  ],
  [AdminRole.OPERATIONS]: [
    AdminRole.OPERATIONS,
    AdminRole.READONLY,
  ],
  [AdminRole.DEVELOPER]: [
    AdminRole.DEVELOPER,
    AdminRole.READONLY,
  ],
  [AdminRole.READONLY]: [
    AdminRole.READONLY,
  ],
};

export function hasAdminRole(userRole: string | undefined, required: AdminRole): boolean {
  if (!userRole) return false;
  const resolved = ADMIN_ROLE_HIERARCHY[userRole as AdminRole];
  if (!resolved) return false;
  return resolved.includes(required);
}
