export const ROUTES = {
  LOGIN: '/login',
  // Post-login role picker for a brand-new user whose /me has no public role yet.
  SELECT_ROLE: '/select-role',
  // Draft legal copy (ui-phase-3) — flagged for human/legal review before launch.
  TERMS: '/terms',
  PRIVACY: '/privacy',

  // Customer (family) app — mobile-first, bottom-tab nav
  HOME: '/',
  // First-login "who is care for?" flow (A3→A4); re-enterable from the patient list.
  ONBOARDING: '/onboarding',
  // Search & discovery (f6) — C1 filter screen; the Home search bar + category tiles navigate here.
  SEARCH: '/search',
  // C2 results list — C1 pushes here carrying the filter set as query params (the deep-linkable key).
  SEARCH_RESULTS: '/search/results',
  // C3 nurse profile base — append `/{nurseId}` (results cards + the booking handoff read this).
  SEARCH_NURSE: '/search/nurse',
  BOOKINGS: '/bookings',
  // C4 booking-request form (f7) — C3's "درخواست رزرو" lands here carrying the nurse + variant + gender.
  BOOKING_REQUEST: '/bookings/request',
  // C5 awaiting-acceptance base — append `/{id}`; create navigates here, the id keys the polled status.
  BOOKING_REQUEST_STATUS: '/bookings/request',
  // Checkout (f9) — C6 summary & pay; the C5 accept CTA hands off here with `?request_id=`.
  CHECKOUT: '/bookings/checkout',
  // Dev mock-gateway harness (test-only stand-in for the PSP redirect; the mock initiate points here).
  CHECKOUT_GATEWAY: '/bookings/checkout/gateway',
  // Return-from-gateway surface — pending-callback poll → succeeded/failed states.
  CHECKOUT_RETURN: '/bookings/checkout/return',
  // Post-payment success screen — links to the booking detail + invoice.
  CHECKOUT_CONFIRMATION: '/bookings/checkout/confirmation',
  // BNPL installment checkout (f11) — the alternate branch off C6: D1 method → D2 plan → D3 eligibility →
  // D4 schedule wizard, reached with `?request_id=`. On a cleared down-payment it routes to the reused
  // confirmation above (the booking confirms exactly as the card path).
  CHECKOUT_BNPL: '/bookings/checkout/bnpl',
  // Provider-handoff harness (test-only stand-in for the provider redirect; the mock initiate points here).
  CHECKOUT_BNPL_GATEWAY: '/bookings/checkout/bnpl/gateway',
  // Return-from-provider surface — settle (down-payment cleared) → confirmation.
  CHECKOUT_BNPL_RETURN: '/bookings/checkout/bnpl/return',
  PATIENTS: '/patients',
  // Address book — cascading region dropdowns + map-pin picker; reached from the profile hub.
  ADDRESSES: '/addresses',
  WALLET: '/wallet',
  PROFILE: '/profile',
  // Support / "My Tickets" (f14) — the only sanctioned post-booking channel; append `/{id}` for a thread.
  SUPPORT_TICKETS: '/support/tickets',
  // In-app notification center (f14) — the polled bell deep-links here and per-notification.
  NOTIFICATIONS: '/notifications',

  // Nurse app
  NURSE: '/nurse',
  NURSE_PROFILE: '/nurse/profile',
  // Services & prices — the nurse variant builder + offerings list (B7 services half).
  NURSE_SERVICES: '/nurse/services',
  // Coverage-area editor — the cities/districts the nurse will travel to (feeds f6 search).
  NURSE_COVERAGE: '/nurse/coverage',
  NURSE_BANK: '/nurse/bank',
  // Incoming booking-requests inbox (f7) — pending requests + accept/reject; append `/{id}` for detail.
  NURSE_REQUESTS: '/nurse/requests',
  // Verification (trust engine) subtree — B3 hub + the staged submission screens (B4/B5/B6).
  NURSE_VERIFICATION: '/nurse/verification',
  NURSE_VERIFICATION_IDENTITY: '/nurse/verification/identity',
  NURSE_VERIFICATION_CREDENTIALS: '/nurse/verification/credentials',
  NURSE_VERIFICATION_REVIEW: '/nurse/verification/review',
  NURSE_VISITS: '/nurse/visits',
  // Earnings & payout history (f12) — the nurse's money home; append `/payouts` for the history list.
  NURSE_EARNINGS: '/nurse/earnings',
  // Payout history list base — append `/{payoutId}` for the payout/batch reconciliation detail.
  NURSE_EARNINGS_PAYOUTS: '/nurse/earnings/payouts',
  // Nurse support / "My Tickets" (f14) — same screens as the customer, under the nurse shell.
  NURSE_SUPPORT_TICKETS: '/nurse/support/tickets',
  // Nurse in-app notification center (f14).
  NURSE_NOTIFICATIONS: '/nurse/notifications',

  // Admin / backoffice console (f15) — desktop sidebar shell, role-gated worklists.
  ADMIN: '/admin',
  ADMIN_USERS: '/admin/users',
  ADMIN_NOTIFICATIONS: '/admin/notifications',
  // Verification review queue — pending nurses; append `/{nurseVerificationId}` for the per-nurse case.
  ADMIN_VERIFICATION: '/admin/verification',
  // Global ticket queue (refund panel opens from a ticket); append `/{id}` for the admin thread.
  ADMIN_TICKETS: '/admin/tickets',
  // Weekly payout dashboard — batch preview → run → detail; append `/{batchId}` for the batch drill-down.
  ADMIN_PAYOUTS: '/admin/payouts',
  // Review moderation queue — publish/hide/reject.
  ADMIN_REVIEWS: '/admin/reviews',
  // Platform config editor + change history.
  ADMIN_CONFIG: '/admin/config',
  // Iranian-holiday calendar manager (drives payout scheduling; is_bank_closed toggle).
  ADMIN_HOLIDAYS: '/admin/holidays',
  // Support-alert triage board — internal-only (assign/resolve).
  ADMIN_ALERTS: '/admin/alerts',
  // Append-only audit-log viewer — read-only, filtered, paginated.
  ADMIN_AUDIT: '/admin/audit',
  // Partner-center management — list/create/verify/activate; append `/{id}` for the center detail.
  ADMIN_PARTNERS: '/admin/partners',
  // RBAC role grid — (DEFERRED-IF-MISSING) built against the mock until the b15 role endpoints land.
  ADMIN_ROLES: '/admin/roles',

  // Partner-center portal (f15) — a SEPARATE authz scope (a center admin is not a Balinyaar admin).
  PARTNER: '/partner',
  PARTNER_NURSES: '/partner/nurses',
  PARTNER_BOOKINGS: '/partner/bookings',
  PARTNER_SETTLEMENT: '/partner/settlement',
} as const;

/** The admin verification case for one nurse (f15) — a queue row deep-links here. */
export const adminVerificationCasePath = (nurseVerificationId: number | string): string =>
  `${ROUTES.ADMIN_VERIFICATION}/${nurseVerificationId}`;

/** The admin ticket thread (f15) — the global queue links here; the refund panel opens inside. */
export const adminTicketThreadPath = (ticketId: number | string): string =>
  `${ROUTES.ADMIN_TICKETS}/${ticketId}`;

/** The admin payout-batch detail (f15) — per-nurse rows, masked IBAN, transfer-reference reconcile. */
export const adminPayoutBatchPath = (batchId: number | string): string =>
  `${ROUTES.ADMIN_PAYOUTS}/${batchId}`;

/** The admin partner-center detail (f15) — verify/activate + sponsored-nurse roster. */
export const adminPartnerCenterPath = (centerId: number | string): string =>
  `${ROUTES.ADMIN_PARTNERS}/${centerId}`;

/** A booking's invoice view (f9) — keyed by the booking the invoice belongs to. */
export const bookingInvoicePath = (bookingId: number | string): string =>
  `${ROUTES.BOOKINGS}/${bookingId}/invoice`;

/** The cancellation flow (f10) — policy-fee disclosure → confirm; keyed by the booking being cancelled. */
export const bookingCancelPath = (bookingId: number | string): string =>
  `${ROUTES.BOOKINGS}/${bookingId}/cancel`;

/** The customer refund-status view (f10) — pending → on-its-way → completed; keyed by the booking. */
export const bookingRefundStatusPath = (bookingId: number | string): string =>
  `${ROUTES.BOOKINGS}/${bookingId}/refund_status`;

/** The nurse's payout/batch reconciliation detail (f12) — keyed by the payout id. */
export const nursePayoutDetailPath = (payoutId: number | string): string =>
  `${ROUTES.NURSE_EARNINGS_PAYOUTS}/${payoutId}`;

/** The nurse's booking-detail view (f8) — earnings rows + payout booking-links deep-link here. */
export const nurseBookingDetailPath = (bookingId: number | string): string =>
  `${ROUTES.NURSE_VISITS}/${bookingId}`;

/** The leave-a-review flow (f13) — the "ثبت نظر" CTA on a completed booking detail lands here. */
export const bookingReviewPath = (bookingId: number | string): string =>
  `${ROUTES.BOOKINGS}/${bookingId}/review`;

/** The E2 patient care-record viewer (f13) — reached by tapping a patient in the Patients tab. */
export const patientRecordPath = (patientId: number | string): string =>
  `${ROUTES.PATIENTS}/${patientId}/record`;

/** A ticket thread (f14) in the **customer** shell. */
export const customerTicketThreadPath = (ticketId: number | string): string =>
  `${ROUTES.SUPPORT_TICKETS}/${ticketId}`;

/** A ticket thread (f14) in the **nurse** shell (same screen, nurse chrome). */
export const nurseTicketThreadPath = (ticketId: number | string): string =>
  `${ROUTES.NURSE_SUPPORT_TICKETS}/${ticketId}`;

/** The tickets inbox base for an actor (customer vs nurse shell). */
export const ticketsBasePath = (role: 'customer' | 'nurse'): string =>
  role === 'nurse' ? ROUTES.NURSE_SUPPORT_TICKETS : ROUTES.SUPPORT_TICKETS;

/** A ticket thread for an actor (customer vs nurse shell). */
export const ticketThreadPath = (role: 'customer' | 'nurse', ticketId: number | string): string =>
  role === 'nurse' ? nurseTicketThreadPath(ticketId) : customerTicketThreadPath(ticketId);

/** The notification center for an actor (customer / nurse / admin shell). */
export const notificationsPath = (role: 'customer' | 'nurse' | 'admin'): string => {
  if (role === 'nurse') return ROUTES.NURSE_NOTIFICATIONS;
  if (role === 'admin') return ROUTES.ADMIN_NOTIFICATIONS;
  return ROUTES.NOTIFICATIONS;
};

/** Paths (without locale prefix) that bypass auth in middleware. */
export const PUBLIC_PATHS: string[] = [ROUTES.LOGIN, ROUTES.TERMS, ROUTES.PRIVACY];

/**
 * Query param the middleware appends when it redirects an unauthenticated deep link to login
 * (e.g. `/fa/bookings/42` → `/fa/login?next=%2Fbookings%2F42`), so `resolvePostLoginDestination`
 * (`services/auth/routing.ts`) can send the user back to where they were headed after OTP.
 */
export const RETURN_URL_PARAM = 'next';
