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

/**
 * The nurse's four-bucket earnings roll-up + the **signed** net payable balance. Read-only; a generous
 * `staleTime` (earnings move weekly, not per second) so revisiting the screen serves from cache. The net
 * balance may be negative ("owed back") — the header renders the sign; this hook never touches the value.
 */
export function useNurseEarningsBalance() {
  return useQuery({
    queryKey: payoutKeys.earningsSummary(),
    queryFn: () => payoutsApi.getNurseEarningsBalance(),
    staleTime: EARNINGS_SUMMARY_STALE_TIME,
    gcTime: PAYOUTS_GC_TIME,
  });
}
