import { keepPreviousData, useQuery } from '@tanstack/react-query';
import { payoutsApi } from '../apis';
import { payoutKeys } from '../keys';
import { PAYOUT_HISTORY_STALE_TIME, PAYOUTS_GC_TIME, PAYOUTS_PAGE_SIZE } from '../constants';

/**
 * The nurse's paginated payout history (`nurse_payouts`, newest first). Each page keys separately;
 * `keepPreviousData` avoids an empty flash while paging. Read-only, generous `staleTime`.
 */
export function useNursePayoutHistory(page: number) {
  return useQuery({
    queryKey: payoutKeys.history(page),
    queryFn: () => payoutsApi.getNursePayoutHistory({ page, pageSize: PAYOUTS_PAGE_SIZE }),
    staleTime: PAYOUT_HISTORY_STALE_TIME,
    gcTime: PAYOUTS_GC_TIME,
    placeholderData: keepPreviousData,
  });
}
