import type { BookingListParams, TodaySessionsParams } from './types';

/**
 * React Query key factory for the bookings domain (hierarchical, per the `services/{domain}` pattern).
 *
 * Sessions are **embedded** in `BookingDetailDto.sessions` (the contract exposes no standalone
 * per-booking session-list endpoint), so `bookingSessions(id)` is an intentional **alias** of
 * `bookingDetail(id)` — the session list is a `select` over the one detail query, never a second fetch.
 * Invalidating `bookingDetail(id)` therefore refreshes the timeline **and** the sessions in one shot.
 * `sessionEvv`/`today` are their own endpoints and their own keys.
 */
export const bookingKeys = {
  all: ['bookings'] as const,

  lists: () => [...bookingKeys.all, 'list'] as const,
  list: (params: BookingListParams) =>
    [...bookingKeys.lists(), params.role, params.status ?? 'all', params.page ?? 1, params.pageSize ?? 0] as const,

  details: () => [...bookingKeys.all, 'detail'] as const,
  bookingDetail: (id: number) => [...bookingKeys.details(), id] as const,
  /** Alias of `bookingDetail` — sessions live inside the detail payload (no separate endpoint). */
  bookingSessions: (id: number) => bookingKeys.bookingDetail(id),

  todayLists: () => [...bookingKeys.all, 'today'] as const,
  today: (params: TodaySessionsParams) =>
    [...bookingKeys.todayLists(), params.date ?? 'today', params.page ?? 1, params.pageSize ?? 0] as const,

  evv: () => [...bookingKeys.all, 'evv'] as const,
  sessionEvv: (sessionId: number) => [...bookingKeys.evv(), sessionId] as const,

  care: () => [...bookingKeys.all, 'care'] as const,
  careInstructions: (bookingId: number) => [...bookingKeys.care(), bookingId] as const,
};
