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

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

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