import { useQuery } from '@tanstack/react-query';
import { fetchWorkerStatuses, type WorkerStatusRow } from '../api';

const QK = ['dashboard', 'workers'] as const;

export function useWorkerStatus() {
  const q = useQuery({
    queryKey: QK,
    queryFn: fetchWorkerStatuses,
    refetchInterval: 5_000,
    staleTime: 0,
  });
  return {
    workers: q.data ?? [],
    isLoading: q.isLoading,
    isError: q.isError,
  };
}

export type { WorkerStatusRow };
