import {
  ROUTES,
  bookingRefundStatusPath,
  nurseBookingDetailPath,
  nursePayoutDetailPath,
  ticketThreadPath,
} from '@/constants';
import type { AppNotification } from './types';

/**
 * Map a notification's parsed `data` to an **app-relative** in-app route (no locale prefix — the caller adds
 * it), role-aware so the same notification lands on the right shell (a booking → the customer's
 * `/bookings/{id}` vs the nurse's `/nurse/visits/{id}`; a ticket → the right `support/tickets/{id}`).
 * Centralised so the bell and the center deep-link identically. Returns `null` when there is nothing to open
 * (`kind: 'none'`, or a target that doesn't apply to this role) — the row is then non-navigable, never broken.
 */
export function notificationDeepLink(notification: AppNotification, role: 'customer' | 'nurse'): string | null {
  const { data } = notification;
  switch (data.kind) {
    case 'booking':
      return role === 'nurse' ? nurseBookingDetailPath(data.bookingId) : `${ROUTES.BOOKINGS}/${data.bookingId}`;
    case 'refund':
      // A refund view is a customer surface; a nurse just reaches the booking.
      return role === 'nurse' ? nurseBookingDetailPath(data.bookingId) : bookingRefundStatusPath(data.bookingId);
    case 'payout':
      return nursePayoutDetailPath(data.payoutId);
    case 'ticket':
      return ticketThreadPath(role, data.ticketId);
    case 'nurse_profile':
      return role === 'customer' ? `${ROUTES.SEARCH_NURSE}/${data.nurseProfileId}` : null;
    case 'none':
    default:
      return null;
  }
}
