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

import type { Workspace } from '@/client/models/Workspace';
import { ReposService } from '@/client/services/ReposService';

export function useAllWorkspaceRepos(workspaces: Workspace[]) {
  return useQueries({
    queries: workspaces.map((ws) => ({
      queryKey: ['workspace', ws.name, 'repos', 'list'],
      queryFn: () =>
        ReposService.repoList({ workspaceName: ws.name, limit: 10 }).then((r) => r.data),
      staleTime: 1000 * 60 * 2,
    })),
  });
}
