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';

/**
 * The center's per-booking commission invoices (portal settlement view). Only meaningful for a
 * merchant-of-record center — a non-MoR center returns an empty page and the portal shows the
 * "settlement runs through Balinyaar" state.
 */
export function useMySettlement(page = 1) {
  return useQuery({
    queryKey: centerKeys.mySettlement({ page, pageSize: PARTNER_PAGE_SIZE }),
    queryFn: () => partnerCenterApi.listMySettlement({ page, pageSize: PARTNER_PAGE_SIZE }),
    staleTime: PARTNER_LIST_STALE_TIME,
    gcTime: PARTNER_GC_TIME,
    placeholderData: keepPreviousData,
  });
}
