export type RoleLane = 'super_admin' | 'admin' | 'concierge' | 'customer';

export const ROLE_LANES = {
  superAdmin: new Set(['Super Administrator']),
  admin: new Set(['Administrator', 'Platform Owner', 'Operations Director', 'Reservations Lead', 'Finance Controller']),
  concierge: new Set(['Concierge Coordinator']),
  customer: new Set(['Customer']),
};

export function getRoleLane(roleName?: string | null, hasGlobalAccess = false): RoleLane {
  if (hasGlobalAccess || (roleName && ROLE_LANES.superAdmin.has(roleName))) {
    return 'super_admin';
  }

  if (roleName && ROLE_LANES.admin.has(roleName)) {
    return 'admin';
  }

  if (roleName && ROLE_LANES.customer.has(roleName)) {
    return 'customer';
  }

  return 'concierge';
}

export function getRoleLaneFromUser(user?: any): RoleLane {
  return getRoleLane(user?.app_role?.name, Boolean(user?.app_role?.globalAccess));
}
