import type { PageParams } from '@/lib/api/types';
import type { ModerationQueueFilters } from './types';

/**
 * React Query key factory for the reviews domain (hierarchical, per the `services/{domain}` pattern).
 *
 * The **nurse id + page** key the public list so paging/revisiting a profile never refetches data already in
 * cache; `eligibility` and `myReviewForBooking` key per booking so the leave-a-review CTA reads its own state
 * independently. A `createReview` mutation invalidates **only** `eligibility` + `myReviewForBooking` for the
 * booking — the public list/aggregate is **never** touched (the new review is `pending_moderation`, not public).
 * A moderation transition (admin) invalidates `moderationQueues()` **and** `nurseLists()` (the affected nurse's
 * public list — its id isn't reachable from the mutation, so all nurse lists are dropped).
 */
export const reviewKeys = {
  all: ['reviews'] as const,

  nurseLists: () => [...reviewKeys.all, 'nurse'] as const,
  /** The public reviews list for a nurse. Pages are managed by `useInfiniteQuery`, so no page in the key. */
  nurse: (nurseProfileId: number) => [...reviewKeys.nurseLists(), nurseProfileId] as const,

  eligibility: (bookingId: number) => [...reviewKeys.all, 'eligibility', bookingId] as const,
  myReviewForBooking: (bookingId: number) => [...reviewKeys.all, 'my_review', bookingId] as const,

  moderationQueues: () => [...reviewKeys.all, 'moderation_queue'] as const,
  /** The admin worklist. Filters + page key the cache so switching a status filter or paging never refetches. */
  moderationQueue: (filters: ModerationQueueFilters, params: PageParams) =>
    [...reviewKeys.moderationQueues(), filters, params] as const,
};
