from youtube_autonomous.segments.builder.ai.enums import ImageEngine, VoiceEngine
from yta_general_utils.programming.parameter_validator import PythonValidator
from yta_general_utils.dataclasses import FileReturn
from yta_general_utils.programming.output import Output
from yta_general_utils.file.enums import FileTypeX
from typing import Union


def create_ai_image(
    prompt: str,
    output_filename: Union[str, None] = None,
    image_engine: ImageEngine = ImageEngine.get_default()
) -> FileReturn:
    """
    Creates an AI image with the provided 'prompt' and stores it locally
    as 'output_filename' (if it is not provided it will generate a 
    temporary file) with the also provided 'image_engine'.

    This method returns the 'output_filename' of the generated image.
    """
    if not PythonValidator.is_string(prompt):
        raise Exception('The "prompt" provided is not a valid string.')
    
    image_engine = (
        ImageEngine.get_default()
        if image_engine is None else
        ImageEngine.to_enum(image_engine)
    )

    return image_engine.generate_image(
        prompt,
        Output.get_filename(output_filename, FileTypeX.IMAGE)
    )

def create_ai_narration(
    text: str,
    output_filename: Union[str, None] = None,
    voice_engine: VoiceEngine = VoiceEngine.get_default()
):
    """
    Creates an audio narration with the given 'text' and stores it
    locally as the 'output_filename' provided (if not provided, it
    generates a temporary file), generated with the also given
    'voice_engine' voice generation engine.

    This method returns the 'output_filename' of the generated audio
    narration.
    """
    if not PythonValidator.is_string(text):
        raise Exception('The "text" parameter provided is not a valid string.')
    
    voice_engine = (
        VoiceEngine.get_default()
        if voice_engine is None else
        VoiceEngine.to_enum(voice_engine)
    )

    return voice_engine.narrate(
        text,
        Output.get_filename(output_filename, FileTypeX.AUDIO)
    )