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

import { ReposService } from '@/client/services/ReposService';

export function useWorkspaceRepos(workspaceName: string | null) {
  return useQuery({
    queryKey: ['workspace', workspaceName, 'repos'],
    queryFn: () => {
      if (!workspaceName) throw new Error('No workspace name');
      return ReposService.repoList({ workspaceName, limit: 50 }).then((r) => r.data);
    },
    enabled: !!workspaceName,
    staleTime: 1000 * 60 * 2,
  });
}
