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

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

export function useRepoStats(workspaceName: string | null, repoName: string | null) {
  return useQuery({
    queryKey: ['repo', workspaceName, repoName, 'stats'],
    queryFn: () => {
      if (!workspaceName || !repoName) throw new Error('Missing params');
      return ReposService.repoGetStats({ workspaceName, repoName }).then((r) => r.data);
    },
    enabled: !!workspaceName && !!repoName,
  });
}
