import { useQuery } from '@tanstack/react-query';
import type { PageParams } from '@/lib/api/types';
import { catalogApi } from '../apis';
import { catalogKeys } from '../keys';
import { CATALOG_REFERENCE_GC_TIME, CATALOG_REFERENCE_STALE_TIME } from '../constants';

/**
 * The active service categories (ordered by `sortOrder`). Admin-seeded **reference data** — cached
 * for the whole session (Infinite `staleTime`), so the Home grid and the builder's step 1 populate
 * once and are served from cache on every revisit. Public (no auth) — always enabled.
 */
export function useServiceCategories(params?: PageParams) {
  return useQuery({
    queryKey: catalogKeys.categories(),
    queryFn: () => catalogApi.listCategories(params),
    staleTime: CATALOG_REFERENCE_STALE_TIME,
    gcTime: CATALOG_REFERENCE_GC_TIME,
  });
}
