# coding: utf-8

"""
    YouTube Data API v3

    The YouTube Data API v3 is an API that provides access to YouTube data, such as videos, playlists, and channels.

    The version of the OpenAPI document: v3
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from youtube_ti.models.video_file_details_audio_stream import VideoFileDetailsAudioStream
from youtube_ti.models.video_file_details_video_stream import VideoFileDetailsVideoStream
from typing import Optional, Set
from typing_extensions import Self

class VideoFileDetails(BaseModel):
    """
    Describes original video file properties, including technical details about audio and video streams, but also metadata information like content length, digitization time, or geotagging information.
    """ # noqa: E501
    audio_streams: Optional[List[VideoFileDetailsAudioStream]] = Field(default=None, description="A list of audio streams contained in the uploaded video file. Each item in the list contains detailed metadata about an audio stream.", alias="audioStreams")
    bitrate_bps: Optional[StrictStr] = Field(default=None, description="The uploaded video file's combined (video and audio) bitrate in bits per second.", alias="bitrateBps")
    container: Optional[StrictStr] = Field(default=None, description="The uploaded video file's container format.")
    creation_time: Optional[StrictStr] = Field(default=None, description="The date and time when the uploaded video file was created. The value is specified in ISO 8601 format. Currently, the following ISO 8601 formats are supported: - Date only: YYYY-MM-DD - Naive time: YYYY-MM-DDTHH:MM:SS - Time with timezone: YYYY-MM-DDTHH:MM:SS+HH:MM ", alias="creationTime")
    duration_ms: Optional[StrictStr] = Field(default=None, description="The length of the uploaded video in milliseconds.", alias="durationMs")
    file_name: Optional[StrictStr] = Field(default=None, description="The uploaded file's name. This field is present whether a video file or another type of file was uploaded.", alias="fileName")
    file_size: Optional[StrictStr] = Field(default=None, description="The uploaded file's size in bytes. This field is present whether a video file or another type of file was uploaded.", alias="fileSize")
    file_type: Optional[StrictStr] = Field(default=None, description="The uploaded file's type as detected by YouTube's video processing engine. Currently, YouTube only processes video files, but this field is present whether a video file or another type of file was uploaded.", alias="fileType")
    video_streams: Optional[List[VideoFileDetailsVideoStream]] = Field(default=None, description="A list of video streams contained in the uploaded video file. Each item in the list contains detailed metadata about a video stream.", alias="videoStreams")
    __properties: ClassVar[List[str]] = ["audioStreams", "bitrateBps", "container", "creationTime", "durationMs", "fileName", "fileSize", "fileType", "videoStreams"]

    @field_validator('file_type')
    def file_type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['video', 'audio', 'image', 'archive', 'document', 'project', 'other']):
            raise ValueError("must be one of enum values ('video', 'audio', 'image', 'archive', 'document', 'project', 'other')")
        return value

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of VideoFileDetails from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in audio_streams (list)
        _items = []
        if self.audio_streams:
            for _item_audio_streams in self.audio_streams:
                if _item_audio_streams:
                    _items.append(_item_audio_streams.to_dict())
            _dict['audioStreams'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in video_streams (list)
        _items = []
        if self.video_streams:
            for _item_video_streams in self.video_streams:
                if _item_video_streams:
                    _items.append(_item_video_streams.to_dict())
            _dict['videoStreams'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of VideoFileDetails from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "audioStreams": [VideoFileDetailsAudioStream.from_dict(_item) for _item in obj["audioStreams"]] if obj.get("audioStreams") is not None else None,
            "bitrateBps": obj.get("bitrateBps"),
            "container": obj.get("container"),
            "creationTime": obj.get("creationTime"),
            "durationMs": obj.get("durationMs"),
            "fileName": obj.get("fileName"),
            "fileSize": obj.get("fileSize"),
            "fileType": obj.get("fileType"),
            "videoStreams": [VideoFileDetailsVideoStream.from_dict(_item) for _item in obj["videoStreams"]] if obj.get("videoStreams") is not None else None
        })
        return _obj


