"use client";

import { useQuery } from "@tanstack/react-query";
import { deliveryApi } from "@/modules/delivery/services/delivery-api";

export function useDeliveryCapabilities() {
  return useQuery({
    queryKey: ["delivery", "capabilities"],
    queryFn: () => deliveryApi.capabilities(),
    staleTime: 60_000,
  });
}

export function useDeliveryHealth() {
  return useQuery({
    queryKey: ["delivery", "health"],
    queryFn: () => deliveryApi.health(),
  });
}

export function useDeliveryMetrics() {
  return useQuery({
    queryKey: ["delivery", "metrics"],
    queryFn: () => deliveryApi.metrics(),
    staleTime: 30_000,
  });
}

export function useDeliveryLookups(tenantId: string | null) {
  return useQuery({
    queryKey: ["delivery", tenantId, "lookups"],
    queryFn: async () => {
      const [organizations, hubs] = await Promise.all([
        deliveryApi.organizations.list(tenantId!, { page: 1, page_size: 500 }),
        deliveryApi.hubs.list(tenantId!, { page: 1, page_size: 500 }),
      ]);
      return { organizations, hubs };
    },
    enabled: !!tenantId,
    staleTime: 30_000,
  });
}
