"""Video Provider Configurations - Based on Latest 2025 API Documentation"""
from app.schemas.provider_config import ProviderConfig, ProviderModel, ProviderControl, ControlOption


# ============== RUNWAY GEN-4 ==============
# Sources: https://docs.dev.runwayml.com/
# https://runwayml.com/news/introducing-runway-api-for-gen-4-images

RUNWAY_CONFIG = ProviderConfig(
    id="runway",
    name="Runway",
    description="Veo 3 and Gen-4 Turbo",
    default_model="veo3",
    models=[
        ProviderModel(
            id="veo3",
            name="Veo 3 (Runway)",
            description="Text or Image to Video (Default)"
        ),
        ProviderModel(
            id="veo3.1",
            name="Veo 3.1 (Runway)",
            description="Latest Veo model"
        ),
        ProviderModel(
            id="gen4_turbo",
            name="Gen-4 Turbo (Image Only)",
            description="High fidelity Image-to-Video"
        )
    ],
    common_controls=[
        ProviderControl(
            name="aspect_ratio",
            label="Aspect Ratio",
            type="select",
            default="1280:720",
            description="Veo (720p) or Gen-4 (1280:768)",
            options=[
                ControlOption(value="1280:720", label="1280:720 (Veo Landscape)"),
                ControlOption(value="720:1280", label="720:1280 (Veo Portrait)"),
                ControlOption(value="1280:768", label="1280:768 (Gen-4 Landscape)"),
                ControlOption(value="768:1280", label="768:1280 (Gen-4 Portrait)")
            ]
        ),
        ProviderControl(
            name="duration",
            label="Duration",
            type="select",
            default=8,
            options=[
                ControlOption(value=5, label="5 seconds (Gen-4)"),
                ControlOption(value=8, label="8 seconds (Veo)"),
                ControlOption(value=10, label="10 seconds (Gen-4)")
            ]
        ),
        ProviderControl(
            name="seed",
            label="Seed",
            type="number",
            default=0,
            min=0,
            max=4294967295,
            description="0 = random",
            required=False
        ),
        ProviderControl(
            name="frame_position",
            label="Frame Position (Image Mode)",
            type="select",
            default="first",
            description="Where to place input image",
            options=[
                ControlOption(value="first", label="First Frame"),
                ControlOption(value="last", label="Last Frame")
            ]
        )
    ],
    features=["gen4_only_image", "veo_supported"]
)


# ============== GOOGLE VEO 3.1 ==============
# Sources: https://ai.google.dev/gemini-api/docs/video
# https://docs.cloud.google.com/vertex-ai/generative-ai/docs/models/veo/3-1-generate

VEO_CONFIG = ProviderConfig(
    id="veo",
    name="Google Veo 3.1",
    description="8-second 1080p video with native audio generation",
    default_model="veo-3.1-generate-preview",
    models=[
        ProviderModel(
            id="veo-3.1-generate-preview",
            name="Veo 3.1",
            description="Latest - native audio, 720p/1080p, frame control"
        ),
        ProviderModel(
            id="veo-3.1-fast-generate-preview",
            name="Veo 3.1 Fast",
            description="Faster generation"
        ),
        ProviderModel(
            id="veo-3.0-generate-001",
            name="Veo 3.0",
            description="Stable version with audio"
        ),
        ProviderModel(
            id="veo-3.0-fast-generate-001",
            name="Veo 3.0 Fast"
        ),
        ProviderModel(
            id="veo-2.0-generate-001",
            name="Veo 2.0 (Legacy)",
            description="720p only, no audio"
        )
    ],
    common_controls=[
        ProviderControl(
            name="aspect_ratio",
            label="Aspect Ratio",
            type="select",
            default="16:9",
            options=[
                ControlOption(value="16:9", label="16:9 (Landscape)"),
                ControlOption(value="9:16", label="9:16 (Portrait)")
            ]
        ),
        ProviderControl(
            name="resolution",
            label="Resolution",
            type="select",
            default="720p",
            description="Veo 3+ supports 1080p",
            options=[
                ControlOption(value="720p", label="720p (1280×720)"),
                ControlOption(value="1080p", label="1080p (1920×1080)")
            ]
        ),
        ProviderControl(
            name="duration",
            label="Duration",
            type="select",
            default=8,
            description="Veo 3 supports 4/6/8 seconds",
            options=[
                ControlOption(value=4, label="4 seconds"),
                ControlOption(value=6, label="6 seconds"),
                ControlOption(value=8, label="8 seconds")
            ]
        ),
        ProviderControl(
            name="sample_count",
            label="Number of Videos",
            type="slider",
            default=1,
            min=1,
            max=4,
            step=1,
            description="Generate multiple variations (1-4)"
        ),
        ProviderControl(
            name="seed",
            label="Seed",
            type="number",
            default=0,
            min=0,
            max=4294967295,
            description="For deterministic generation (0 = random)",
            required=False
        ),
        ProviderControl(
            name="negative_prompt",
            label="Negative Prompt",
            type="textarea",
            default="",
            description="Unwanted elements",
            required=False
        ),
        ProviderControl(
            name="person_generation",
            label="Person Generation",
            type="select",
            default="",
            required=False,
            description="Safety setting for people/faces",
            options=[
                ControlOption(value="", label="Default"),
                ControlOption(value="allow_adult", label="Allow Adult Faces Only")
            ]
        )
    ],
    features=["native_audio", "frame_control", "reference_images_up_to_3", "video_extension", "1080p"]
)


# ============== MASTER DICTIONARY ==============

VIDEO_PROVIDER_CONFIGS = {
    "runway": RUNWAY_CONFIG,
    "veo": VEO_CONFIG
}


def get_video_provider_configs() -> dict:
    """Get all video provider configs as JSON-serializable dict"""
    return {
        provider_id: config.model_dump(by_alias=True)
        for provider_id, config in VIDEO_PROVIDER_CONFIGS.items()
    }
