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

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

export function useAllWorkspaceIssues(workspaces: Workspace[]) {
  return useQueries({
    queries: workspaces.map((ws) => ({
      queryKey: ['workspace', ws.name, 'issues', 'list'],
      queryFn: () =>
        IssuesService.issueList({
          workspaceName: ws.name,
          state: 'open',
          limit: 10,
        }).then((r) => r.data),
      staleTime: 1000 * 60 * 2,
    })),
  });
}
