import { useQuery } from '@tanstack/react-query';
import type { PageParams } from '@/lib/api/types';
import { patientsApi } from '../apis';
import { patientKeys } from '../keys';
import { PATIENTS_STALE_TIME } from '../constants';

/**
 * Fetches the patients list. A deliberate staleTime keeps the list warm across remounts
 * so navigating away and back doesn't refetch what's already cached.
 */
export function usePatients(params?: PageParams) {
  return useQuery({
    queryKey: patientKeys.list(params),
    queryFn: () => patientsApi.list(params),
    staleTime: PATIENTS_STALE_TIME,
  });
}
