import { useQuery } from '@tanstack/react-query';
import api from '@/lib/api';
import type { MetricsResponse } from '@/types/api';

const METRICS_KEY = 'metrics';

export function useMetrics(scenarioId: string) {
  return useQuery<MetricsResponse>({
    queryKey: [METRICS_KEY, scenarioId],
    queryFn: async () => {
      const response = await api.get(`/scenarios/${scenarioId}/metrics`);
      return response.data;
    },
    enabled: !!scenarioId,
    refetchInterval: 5000, // Refresh every 5 seconds for running scenarios
  });
}
