import type { PageParams } from '@/lib/api/types'; /** * React Query key factory for the catalog domain. Reference data (categories, a category's option * groups) is keyed so each is fetched **once** per session and served from cache across the Home * grid and the nurse builder. The nurse's own variant list invalidates on every mutation via the * `myVariantsLists()` prefix; a single edited variant is refreshed by `variant(id)`. */ export const catalogKeys = { all: ['catalog'] as const, // Reference data — cached for the whole session, never invalidated by this phase. categories: () => [...catalogKeys.all, 'categories'] as const, /** Prefix shared by every `categoryOptionGroups(id)` key — invalidate this to catch every cached * category when a group/value edit is cross-category (its `serviceCategoryId` is null) or its exact * category set isn't known to the caller. */ categoryOptionGroupsAll: () => [...catalogKeys.all, 'option-groups'] as const, categoryOptionGroups: (categoryId?: number | null) => [...catalogKeys.categoryOptionGroupsAll(), categoryId ?? null] as const, // The nurse's offerings — mutable; mutations invalidate the `myVariantsLists()` prefix. variants: () => [...catalogKeys.all, 'variants'] as const, myVariantsLists: () => [...catalogKeys.variants(), 'mine'] as const, myVariants: (params?: PageParams) => [...catalogKeys.myVariantsLists(), params ?? {}] as const, variant: (id: number) => [...catalogKeys.variants(), 'detail', id] as const, // Admin catalog management — separate from the public/cached reference-data keys above so a mutation // invalidating one never stales the other's cache entry. admin: () => [...catalogKeys.all, 'admin'] as const, adminCategoryLists: () => [...catalogKeys.admin(), 'categories'] as const, adminCategories: (params?: PageParams) => [...catalogKeys.adminCategoryLists(), params ?? {}] as const, /** Prefix shared by every `adminOptionGroups(id)` key — see `categoryOptionGroupsAll`'s doc for why a * group/value mutation invalidates this prefix instead of a single category id. */ adminOptionGroupsAll: () => [...catalogKeys.admin(), 'option-groups'] as const, adminOptionGroups: (categoryId: number) => [...catalogKeys.adminOptionGroupsAll(), categoryId] as const, };