import { useMutation, useQuery } from '@tanstack/react-query';
import { apiClient } from '@/api/client';
import type { BillingCadence } from '@/api/types';

/** Plan + quota summary. Member-accessible (sourced from `/usage`). */
export function useNetworkUsage(networkId: string) {
  return useQuery({
    queryKey: ['network-usage', networkId],
    queryFn: () => apiClient.getNetworkUsage(networkId),
  });
}

/** Full billing status. Admin-gated (`/billing`). */
export function useNetworkBilling(networkId: string, enabled: boolean) {
  return useQuery({
    queryKey: ['network-billing', networkId],
    queryFn: () => apiClient.getNetworkBilling(networkId),
    enabled,
  });
}

export function useCreateCheckoutSession(networkId: string) {
  return useMutation({
    mutationFn: (cadence: BillingCadence) =>
      apiClient.createCheckoutSession(networkId, cadence),
  });
}

export function useCreatePortalSession(networkId: string) {
  return useMutation({
    mutationFn: () => apiClient.createPortalSession(networkId),
  });
}
