import { useQuery } from '@tanstack/react-query';
import { geographyApi } from '../apis';
import { geographyKeys } from '../keys';
import { GEO_GC_TIME, GEO_STALE_TIME } from '../constants';

/**
 * The active provinces (ordered). Reference data — cached for the whole session (Infinite
 * `staleTime`), so the province dropdown is populated once and served from cache on every
 * revisit and across both editors.
 */
export function useProvinces() {
  return useQuery({
    queryKey: geographyKeys.provinces(),
    queryFn: () => geographyApi.listProvinces(),
    staleTime: GEO_STALE_TIME,
    gcTime: GEO_GC_TIME,
  });
}
