#!/usr/bin/env python3
"""
Genesis Vids Automator
======================
Automates the creation of video presentations in Google Vids 
using Veo 3.1 avatars and synthesized content.

Features:
- Scene script generation
- Avatar video generation (via VeoAgent)
- Audio synthesis (via TTSAgent)
- Assembly instructions for Google Vids

Usage:
    from vids_automator import VidsAutomator
    automator = VidsAutomator()
    automator.create_presentation("Introduction to Genesis Evolution")
"""

import os
import sys
import json
from datetime import datetime
from pathlib import Path
from typing import List, Dict, Any

# Add genesis-system to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

from veo_generator import VeoAgent
from tts_generator import TTSAgent
from notebook_lm_skill import NotebookLMAgent

class VidsAutomator:
    """
    Agent that orchestrates multimodal generation specifically
    for Google Vids presentations.
    """
    
    def __init__(self):
        self.veo = VeoAgent()
        self.tts = TTSAgent()
        self.notebook = NotebookLMAgent()
        
        print(f"[OK] Vids Automator Initialized")
    
    def create_presentation(self, mission_summary: str) -> Dict[str, Any]:
        """
        Creates a multimodal video package for a presentation.
        """
        print(f"[VIDS] Animating mission: {mission_summary}")
        
        # 1. Synthesize content script
        research = self.notebook.deep_research(mission_summary, depth=1)
        script_text = research.get("report", "Genesis Evolution is the mission.")[:500]
        
        # 2. Generate Audio (TTS)
        print("[VIDS] Generating speech...")
        audio = self.tts.generate(script_text, voice_style="professional, cinematic, clear")
        
        # 3. Generate Avatar Video (Veo)
        print("[VIDS] Generating avatar video (can be slow)...")
        # For demo purposes, we do it asynchronously if it's a real run
        video = self.veo.generate(
            prompt=f"A professional AI avatar presenting: {mission_summary[:50]}",
            generate_audio=False,
            wait_for_completion=False # Async for speed in coordinator
        )
        
        return {
            "title": mission_summary,
            "script": script_text,
            "audio_path": audio.get("path"),
            "video_operation_id": video.get("operation_id"),
            "status": "in_assembly",
            "timestamp": datetime.now().isoformat()
        }

if __name__ == "__main__":
    automator = VidsAutomator()
    print("[TEST] Vids Automator Ready")
    # result = automator.create_presentation("Genesis Multimodal Mastery")
    # print(f"Presentation status: {result['status']}")
