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

import { useApiClient } from '@/lib/apiClient';

interface GenerateTextPromptParams {
  clipId: string;
  target: 'image' | 'video';
  prompt: string | null;
}

export function useGenerateTextPrompt() {
  const apiClient = useApiClient();

  const mutation = useMutation({
    mutationFn: async (params: GenerateTextPromptParams) => {
      const { data, error } = await apiClient.POST(
        '/api/video_gen/text/generate',
        {
          body: {
            clip_id: params.clipId,
            target: params.target,
            user_prompt: params.prompt,
          },
        }
      );

      if (error || !data) {
        throw new Error('Failed to generate text prompt');
      }

      return data;
    },
  });

  return mutation.mutateAsync;
}
