import { useQuery } from '@tanstack/react-query';
import { bnplApi } from '../apis';
import { bnplKeys } from '../keys';
import { BNPL_OPTIONS_STALE_TIME } from '../constants';

/**
 * D1/D2 — the payable amount + the provider/plan set for an accepted request. Short `staleTime`
 * (the price/deadline can move between visits). Enabled only when an id is present.
 */
export function useBnplOptions(bookingRequestId: number | undefined) {
  return useQuery({
    queryKey: bnplKeys.options(bookingRequestId ?? -1),
    queryFn: () => bnplApi.getBnplOptions(bookingRequestId as number),
    enabled: bookingRequestId != null && bookingRequestId > 0,
    staleTime: BNPL_OPTIONS_STALE_TIME,
  });
}
