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

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

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