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

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

export function useWikiPage(
  workspaceName: string | null,
  repoName: string | null,
  slug: string | null,
) {
  return useQuery({
    queryKey: ['workspace', workspaceName, 'repos', repoName, 'wiki', slug],
    queryFn: () => {
      if (!workspaceName || !repoName || !slug) throw new Error('Missing params');
      return WikiService.wikiGetPage({ workspaceName, repoName, slug }).then((r) => r.data);
    },
    enabled: !!workspaceName && !!repoName && !!slug,
    staleTime: 1000 * 60 * 2,
  });
}
