import { useQuery } from "@tanstack/react-query";
import { api } from "@/api/client";
import { queryKeys } from "@/lib/query-keys";
import type { AgentValidation, Resource, ResourceDetail } from "@/api/types";

export function useAgentValidation(name: string | undefined) {
  return useQuery({
    queryKey: queryKeys.registry.validate(name ?? ""),
    queryFn: () => api.get<AgentValidation>(`/registry/agents/${name}/validate`),
    enabled: !!name,
  });
}

export function useResources(
  type: string,
  options?: { enabled?: boolean },
) {
  return useQuery({
    queryKey: queryKeys.registry.list(type),
    queryFn: () => api.get<Resource[]>(`/registry/${type}`),
    enabled: options?.enabled,
  });
}

export function useResourceDetail(
  type: string,
  name: string,
  options?: { enabled?: boolean },
) {
  return useQuery({
    queryKey: queryKeys.registry.detail(type, name),
    queryFn: () => api.get<ResourceDetail>(`/registry/${type}/${name}`),
    enabled: options?.enabled ?? !!name,
  });
}
