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

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

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