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

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

export function useGitCommit(
  workspaceName: string | null,
  repoName: string | null,
  revision: string | null,
) {
  return useQuery({
    queryKey: ['repo', workspaceName, repoName, 'git', 'commit', revision],
    queryFn: () => {
      if (!workspaceName || !repoName || !revision) throw new Error('Missing params');
      return GitService.gitGetCommit({ workspaceName, repoName, revision }).then((r) => r.data);
    },
    enabled: !!workspaceName && !!repoName && !!revision,
    staleTime: 1000 * 60 * 5,
  });
}
