import { useQueries } from '@tanstack/react-query';

import type { WorkspaceDetail } from '@/client/models/WorkspaceDetail';
import { WorkspacesService } from '@/client/services/WorkspacesService';

export function useAllWorkspaceStats(workspaces: WorkspaceDetail[]) {
  return useQueries({
    queries: workspaces.map((ws) => ({
      queryKey: ['workspace', ws.name, 'stats'],
      queryFn: () =>
        WorkspacesService.workspaceGetStats({ workspaceName: ws.name }).then((r) => r.data),
      staleTime: 1000 * 60 * 2,
    })),
  });
}
