"use client";

import { useQuery } from "@tanstack/react-query";
import {
  communicationApi,
  normalizeCapabilities,
} from "@/modules/communication/services/communication-api";

export function useCommunicationCapabilities() {
  return useQuery({
    queryKey: ["communication", "capabilities"],
    queryFn: async () => normalizeCapabilities(await communicationApi.capabilities()),
    staleTime: 60_000,
  });
}

export function useCommunicationHealth() {
  return useQuery({
    queryKey: ["communication", "health"],
    queryFn: () => communicationApi.health(),
  });
}

export function useCommunicationHealthReady() {
  return useQuery({
    queryKey: ["communication", "health-ready"],
    queryFn: () => communicationApi.healthReady(),
  });
}

export function useCommunicationMetrics() {
  return useQuery({
    queryKey: ["communication", "metrics"],
    queryFn: () => communicationApi.metrics(),
    staleTime: 30_000,
  });
}

export function useCommunicationMonitoring(tenantId: string | null) {
  return useQuery({
    queryKey: ["communication", tenantId, "monitoring-stats"],
    queryFn: () => communicationApi.monitoring.stats(tenantId!),
    enabled: !!tenantId,
    staleTime: 15_000,
  });
}

export function useCommunicationLookups(_tenantId: string | null) {
  return {
    isLoading: false,
    data: { providers: [] as Record<string, unknown>[] },
  };
}

export function isFeatureEnabled(
  features: Record<string, boolean> | undefined,
  feature: string
): boolean {
  if (!features) return false;
  return features[feature] === true;
}
