from youtube_autonomous.elements.builder.element_builder import ElementBuilder
from youtube_autonomous.segments.enums import SegmentField, EnhancementField
from youtube_autonomous.elements.validator.element_parameter_validator import ElementParameterValidator
from typing import Union


class AIVideoElementBuilder(ElementBuilder):
    """
    Builder to obtain videos generated with AI.
    """

    @classmethod
    def build_from_enhancement(
        cls,
        enhancement: dict
    ):
        # TODO: I should always have 'calculated_duration' when duration
        # has been processed
        return cls._build(
            enhancement.get(EnhancementField.KEYWORDS.value, None),
            enhancement.get('duration', None)
        )

    @classmethod
    def build_from_segment(
        cls,
        segment: dict
    ):
        # TODO: I should always have 'calculated_duration' when duration
        # has been processed
        return cls._build(
            segment.get(SegmentField.KEYWORDS.value, None),
            segment.get('duration', None)
        )

    @classmethod
    def _build(cls, keywords: str, duration: Union[float, int]):
        ElementParameterValidator.validate_keywords(keywords)
        ElementParameterValidator.validate_duration(duration)

        raise Exception('Functionality not implemented yet.')
    
        # TODO: Build a video from some AI
        # video = create_ai_video(keywords, duration)

        return video