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

/**
 * React Query key factory for the verification domain. The nurse's own `status()` is the **single
 * cached source** that both B3 (checklist) and B6 (under-review) read — one query, two views. Every
 * submit/upload/run mutation invalidates `status()` so the checklist re-renders from cache with no
 * manual refetch. The public `badge(nurseId)` is longer-lived and reused by search/f6.
 *
 * The admin subtree (`admin()` → queue / case / document-url) mirrors the same hierarchy: each queue
 * variant (filters+params) and each case keys independently, and the `adminQueues()` / `adminCases()`
 * prefixes let a decision invalidate every queue page and a single case in one call.
 */
export const verificationKeys = {
  all: ['verification'] as const,

  // The signed-in nurse's checklist — moderately fresh; every mutation invalidates it.
  status: () => [...verificationKeys.all, 'status'] as const,

  // A manual step's uploaded documents (metadata only), if a screen ever lists them separately.
  documents: (stepCode: string) => [...verificationKeys.all, 'documents', stepCode] as const,

  // The public trust badge — keyed per nurse; reused by the own-profile view and f6 search/profile.
  badge: (nurseId: number) => [...verificationKeys.all, 'badge', nurseId] as const,

  // --- Admin review queue (b6 AdminVerificationsController) ---
  admin: () => [...verificationKeys.all, 'admin'] as const,

  // The review queue — `filters` + `params` are part of the key, so paging / changing the status filter
  // never refetches a page already in cache (React Query hashes keys deterministically).
  adminQueues: () => [...verificationKeys.admin(), 'queue'] as const,
  adminQueue: (filters: AdminVerificationQueueFilters, params: PageParams) =>
    [...verificationKeys.adminQueues(), filters, params] as const,

  // A single nurse's full case — invalidated on every decide / approve / reject.
  adminCases: () => [...verificationKeys.admin(), 'case'] as const,
  adminCase: (nurseVerificationId: number) => [...verificationKeys.adminCases(), nurseVerificationId] as const,

  // A document's short-lived signed URL — keyed per document; kept out of long-term cache (fetched on demand).
  adminDocumentUrls: () => [...verificationKeys.admin(), 'document_url'] as const,
  adminDocumentUrl: (documentId: number) => [...verificationKeys.adminDocumentUrls(), documentId] as const,
};
