import { useMutation, useQueryClient } from '@tanstack/react-query';

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

export function useDeleteWikiPage(workspaceName: string | null, repoName: string | null) {
  const qc = useQueryClient();

  return useMutation({
    mutationFn: (slug: string) => {
      if (!workspaceName || !repoName) throw new Error('Missing params');
      return WikiService.wikiDeletePage({ workspaceName, repoName, slug });
    },
    onSuccess: () => {
      qc.invalidateQueries({
        queryKey: ['workspace', workspaceName, 'repos', repoName, 'wiki'],
      });
    },
  });
}
