"use client"

import { useMutation } from "@tanstack/react-query"
import { apiClient } from "@/lib/api/client"
import type { ApiLLMModelsResponse } from "@/lib/contacts/discovery-types"

export function useDiscoverOrgLLMModels() {
  return useMutation({
    mutationFn: (providerId: string) =>
      apiClient.post<ApiLLMModelsResponse>("/admin/org/llm/discover-models", {
        provider_id: providerId,
      }),
  })
}

export function isOrgLLMProviderKeyConfigured(
  secrets: Record<string, unknown> | undefined,
  providerId: string,
): boolean {
  const llmProviders = secrets?.llm_providers
  if (!llmProviders || typeof llmProviders !== "object") return false
  const entry = (llmProviders as Record<string, { configured?: boolean }>)[providerId]
  return entry?.configured === true
}
