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

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

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