"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from openrouter.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
    UnrecognizedStr,
)
from openrouter.utils import validate_open_enum
from pydantic import model_serializer
from pydantic.functional_validators import PlainValidator
from typing import Dict, List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


SupportedAspectRatio = Union[
    Literal[
        "16:9",
        "9:16",
        "1:1",
        "4:3",
        "3:4",
        "3:2",
        "2:3",
        "21:9",
        "9:21",
    ],
    UnrecognizedStr,
]


SupportedFrameImage = Union[
    Literal[
        "first_frame",
        "last_frame",
    ],
    UnrecognizedStr,
]


SupportedResolution = Union[
    Literal[
        "480p",
        "720p",
        "1080p",
        "1K",
        "2K",
        "4K",
    ],
    UnrecognizedStr,
]


SupportedSize = Union[
    Literal[
        "480x480",
        "480x640",
        "480x720",
        "480x854",
        "480x1120",
        "640x480",
        "720x480",
        "720x720",
        "720x960",
        "720x1080",
        "720x1280",
        "720x1680",
        "854x480",
        "960x720",
        "1080x720",
        "1080x1080",
        "1080x1440",
        "1080x1620",
        "1080x1920",
        "1080x2520",
        "1120x480",
        "1280x720",
        "1440x1080",
        "1620x1080",
        "1680x720",
        "1920x1080",
        "2160x2160",
        "2160x2880",
        "2160x3240",
        "2160x3840",
        "2160x5040",
        "2520x1080",
        "2880x2160",
        "3240x2160",
        "3840x2160",
        "5040x2160",
    ],
    UnrecognizedStr,
]


class VideoModelTypedDict(TypedDict):
    allowed_passthrough_parameters: List[str]
    r"""List of parameters that are allowed to be passed through to the provider"""
    canonical_slug: str
    r"""Canonical slug for the model"""
    created: int
    r"""Unix timestamp of when the model was created"""
    generate_audio: Nullable[bool]
    r"""Whether the model supports generating audio alongside video"""
    id: str
    r"""Unique identifier for the model"""
    name: str
    r"""Display name of the model"""
    seed: Nullable[bool]
    r"""Whether the model supports deterministic generation via seed parameter"""
    supported_aspect_ratios: Nullable[List[SupportedAspectRatio]]
    r"""Supported output aspect ratios"""
    supported_durations: Nullable[List[int]]
    r"""Supported video durations in seconds"""
    supported_frame_images: Nullable[List[SupportedFrameImage]]
    r"""Supported frame image types (e.g. first_frame, last_frame)"""
    supported_resolutions: Nullable[List[SupportedResolution]]
    r"""Supported output resolutions"""
    supported_sizes: Nullable[List[SupportedSize]]
    r"""Supported output sizes (width x height)"""
    description: NotRequired[str]
    r"""Description of the model"""
    hugging_face_id: NotRequired[Nullable[str]]
    r"""Hugging Face model identifier, if applicable"""
    pricing_skus: NotRequired[Nullable[Dict[str, str]]]
    r"""Pricing SKUs with provider prefix stripped, values as strings"""


class VideoModel(BaseModel):
    allowed_passthrough_parameters: List[str]
    r"""List of parameters that are allowed to be passed through to the provider"""

    canonical_slug: str
    r"""Canonical slug for the model"""

    created: int
    r"""Unix timestamp of when the model was created"""

    generate_audio: Nullable[bool]
    r"""Whether the model supports generating audio alongside video"""

    id: str
    r"""Unique identifier for the model"""

    name: str
    r"""Display name of the model"""

    seed: Nullable[bool]
    r"""Whether the model supports deterministic generation via seed parameter"""

    supported_aspect_ratios: Nullable[
        List[Annotated[SupportedAspectRatio, PlainValidator(validate_open_enum(False))]]
    ]
    r"""Supported output aspect ratios"""

    supported_durations: Nullable[List[int]]
    r"""Supported video durations in seconds"""

    supported_frame_images: Nullable[
        List[Annotated[SupportedFrameImage, PlainValidator(validate_open_enum(False))]]
    ]
    r"""Supported frame image types (e.g. first_frame, last_frame)"""

    supported_resolutions: Nullable[
        List[Annotated[SupportedResolution, PlainValidator(validate_open_enum(False))]]
    ]
    r"""Supported output resolutions"""

    supported_sizes: Nullable[
        List[Annotated[SupportedSize, PlainValidator(validate_open_enum(False))]]
    ]
    r"""Supported output sizes (width x height)"""

    description: Optional[str] = None
    r"""Description of the model"""

    hugging_face_id: OptionalNullable[str] = UNSET
    r"""Hugging Face model identifier, if applicable"""

    pricing_skus: OptionalNullable[Dict[str, str]] = UNSET
    r"""Pricing SKUs with provider prefix stripped, values as strings"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["description", "hugging_face_id", "pricing_skus"]
        nullable_fields = [
            "generate_audio",
            "hugging_face_id",
            "pricing_skus",
            "seed",
            "supported_aspect_ratios",
            "supported_durations",
            "supported_frame_images",
            "supported_resolutions",
            "supported_sizes",
        ]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m
