import { useQuery } from '@tanstack/react-query';
import { bookingsApi } from '../apis';
import { bookingKeys } from '../keys';
import { BOOKINGS_PAGE_SIZE, TODAY_SESSIONS_STALE_TIME } from '../constants';
import type { TodaySessionsParams } from '../types';

/**
 * The nurse's "today" session feed (`booking_sessions/today`) — the ویزیت امروز surface. Kept fresh (short
 * `staleTime`) and **invalidated on every EVV mutation** so a check-in/out flips the row's CTA state
 * without a manual refresh. `date` omitted = the server's today.
 */
export function useTodaySessions(options?: { date?: string; page?: number; pageSize?: number }) {
  const params: TodaySessionsParams = {
    date: options?.date,
    page: options?.page ?? 1,
    pageSize: options?.pageSize ?? BOOKINGS_PAGE_SIZE,
  };
  return useQuery({
    queryKey: bookingKeys.today(params),
    queryFn: () => bookingsApi.listTodaySessions(params),
    staleTime: TODAY_SESSIONS_STALE_TIME,
  });
}
