import { useQuery } from "@tanstack/react-query";

import { QUERY_KEYS } from "@/constants/QUERY_KEYS";
import { bookingOrdersService } from "@/services/booking-orders.service";

/** Orders placed against a general contract (id = the contract booking id). */
export function useContractOrders(
  contractBookingId: string | undefined,
  enabled = true,
) {
  return useQuery({
    queryKey: QUERY_KEYS.BOOKING_ORDERS.byContract(contractBookingId ?? ""),
    queryFn: () => bookingOrdersService.listByContract(contractBookingId!),
    enabled: Boolean(contractBookingId) && enabled,
  });
}

/** Contracted / ordered / remaining drawdown pool for a general contract. */
export function useContractPool(
  contractBookingId: string | undefined,
  enabled = true,
) {
  return useQuery({
    queryKey: QUERY_KEYS.BOOKING_ORDERS.pool(contractBookingId ?? ""),
    queryFn: () => bookingOrdersService.pool(contractBookingId!),
    enabled: Boolean(contractBookingId) && enabled,
  });
}
