import { useQuery } from '@tanstack/react-query';
import { searchApi } from '../apis';
import { searchKeys } from '../keys';
import { SEARCH_GC_TIME, SEARCH_PROFILE_STALE_TIME } from '../constants';

/**
 * The C3 nurse-profile query, keyed on `searchKeys.profile(nurseId)` and enabled only when an id is
 * present. Cached for the stale window so returning from the booking handoff serves from cache.
 */
export function useNurseProfile(nurseId: number | undefined) {
  return useQuery({
    queryKey: searchKeys.profile(nurseId ?? -1),
    queryFn: () => searchApi.getNurseProfile(nurseId as number),
    enabled: nurseId != null,
    staleTime: SEARCH_PROFILE_STALE_TIME,
    gcTime: SEARCH_GC_TIME,
  });
}
