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

/**
 * One payout expanded — the nurse's reconciliation view (money decomposition + batch window + the exact
 * bookings covered). A settled payout is immutable, so a long `staleTime`; disabled until a valid id.
 */
export function useNursePayoutDetail(payoutId: number | undefined) {
  return useQuery({
    queryKey: payoutKeys.detail(payoutId ?? -1),
    queryFn: () => payoutsApi.getNursePayoutDetail(payoutId as number),
    enabled: payoutId != null && payoutId > 0,
    staleTime: PAYOUT_DETAIL_STALE_TIME,
    gcTime: PAYOUTS_GC_TIME,
  });
}
