import { keepPreviousData, useQuery } from '@tanstack/react-query';
import { partnerCenterApi } from '../apis';
import { centerKeys } from '../keys';
import { PARTNER_GC_TIME, PARTNER_LIST_STALE_TIME, PARTNER_PAGE_SIZE } from '../constants';
import type { SponsoredBookingFilters } from '../types';

/** The bookings the signed-in center legally covers (portal; read-only summaries). Filter+page key cache. */
export function useMySponsoredBookings(filters: SponsoredBookingFilters, page = 1) {
  return useQuery({
    queryKey: centerKeys.mySponsoredBookings(filters, { page, pageSize: PARTNER_PAGE_SIZE }),
    queryFn: () => partnerCenterApi.listMySponsoredBookings(filters, { page, pageSize: PARTNER_PAGE_SIZE }),
    staleTime: PARTNER_LIST_STALE_TIME,
    gcTime: PARTNER_GC_TIME,
    placeholderData: keepPreviousData,
  });
}
