import { useQuery } from '@tanstack/react-query';
import { fetchSubtaskActivities, fetchSubtaskActivity } from '../api';
import { POLLING } from '../lib/constants.js';

export function useSubtaskActivities(taskId: number | null, enabled: boolean) {
  return useQuery({
    queryKey: ['subtaskActivities', taskId],
    queryFn: () => fetchSubtaskActivities(taskId!),
    refetchInterval: enabled ? POLLING.FAST : false,
    enabled: enabled && taskId !== null,
  });
}

export function useSubtaskActivity(taskId: number | null, jobId: string | null, enabled: boolean) {
  return useQuery({
    queryKey: ['subtaskActivity', taskId, jobId],
    queryFn: () => fetchSubtaskActivity(taskId!, jobId!),
    refetchInterval: enabled ? POLLING.FAST : false,
    enabled: enabled && taskId !== null && jobId !== null,
  });
}
