import type { BookabilityWidener } from './bookabilityReasons'; // Config that is silently BROADER than the practice probably intended. // // These are NOT defects and are NOT being removed. The permissive fallbacks are exactly what lets a solo // practitioner skip four of six configuration steps and still be bookable - removing them would make setup // HARDER for the practices this product is aimed at. The defect is that they are invisible, so we narrate // them and change nothing about how they behave. // // A widening is only worth reporting when there is something to widen TO: a one-service org offering "all // services" has widened nothing, and saying so would be pure noise for the smallest practices. export interface WidenerInput { /** Size of PractitionerRole.healthcareService. 0 the schedule modal falls back to the whole catalog. */ practitionerOfferedServiceCount: number; orgCatalogSize: number; /** Size of HealthcareService.location. 0 "offered at all locations". */ serviceLocationCount: number; orgLocationCount: number; /** Whether a self-bookable extension was written at ANY of the three levels. */ selfBookableSetExplicitly: boolean; } export function detectWideners(input: WidenerInput): BookabilityWidener[] { const wideners: BookabilityWidener[] = []; if (input.practitionerOfferedServiceCount === 0 && input.orgCatalogSize > 1) { wideners.push('WIDENED_ALL_SERVICES'); } if (input.serviceLocationCount === 0 && input.orgLocationCount > 1) { wideners.push('WIDENED_ALL_LOCATIONS'); } if (!input.selfBookableSetExplicitly) { wideners.push('WIDENED_SELF_BOOKABLE_BY_DEFAULT'); } return wideners; }