import datetime
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar, Union, cast
from uuid import UUID

from attrs import define as _attrs_define
from dateutil.parser import isoparse

from ..models.video_stream_inputs_model_audio_ambience_channel import VideoStreamInputsModelAudioAmbienceChannel
from ..models.video_stream_inputs_model_audio_commentary_channel import VideoStreamInputsModelAudioCommentaryChannel
from ..models.video_stream_inputs_model_feed_type import VideoStreamInputsModelFeedType
from ..models.video_stream_inputs_model_input_resolution import VideoStreamInputsModelInputResolution
from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.video_stream_inputs_model_competition import VideoStreamInputsModelCompetition
    from ..models.video_stream_inputs_model_fixture import VideoStreamInputsModelFixture
    from ..models.video_stream_inputs_model_organization import VideoStreamInputsModelOrganization
    from ..models.video_stream_inputs_model_venue import VideoStreamInputsModelVenue


T = TypeVar("T", bound="VideoStreamInputsModel")


@_attrs_define
class VideoStreamInputsModel:
    """
    Attributes:
        video_input_id (Union[Unset, UUID]): The unique identifier of the video input Example:
            009e9276-5c80-11e8-9c2d-fa7ae01bbebc.
        master_venue_id (Union[Unset, UUID]): The unique identifier of the master venue Example:
            009e9276-5c80-11e8-9c2d-fa7ae01bbebc.
        organization_id (Union[Unset, str]): The unique identifier of the organization Example: 9.
        organization (Union[Unset, VideoStreamInputsModelOrganization]): The organization that this Video Stream Inputs
            belongs to
        venue_id (Union[Unset, UUID]): The unique identifier of the venue Example: 009e9276-5c80-11e8-9c2d-fa7ae01bbebc.
        venue (Union[Unset, VideoStreamInputsModelVenue]): The venue that this match belongs to
        competition_id (Union[Unset, UUID]): The unique identifier of the competition Example:
            009e9276-5c80-11e8-9c2d-fa7ae01bbebc.
        competition (Union[Unset, VideoStreamInputsModelCompetition]): The competition that this season belongs to
        fixture_id (Union[Unset, UUID]): The unique identifier of the match Example:
            009e9276-5c80-11e8-9c2d-fa7ae01bbebc.
        fixture (Union[Unset, VideoStreamInputsModelFixture]): The match
        start_time_local (Union[Unset, datetime.datetime]): Start time (Local). Example: 2018-08-16T02:00:00.
        start_time_utc (Union[Unset, datetime.datetime]): Start time (UTC). This is automatically generated based on the
            timezone of the venue. Example: 2018-08-16T02:00:00.
        finish_recording_time_utc (Union[Unset, datetime.datetime]): (TO BE REMOVED) Finish Recording time of the stream
            (if not set, is calculated as startTimeUTC + durationFull from matches)
        estimated_finish_time_utc (Union[Unset, datetime.datetime]): Finish Recording time of the stream (if not set, is
            calculated as startTimeUTC + durationFull from matches)
        provider (Union[Unset, str]): The code for the provider of the file Example: Test Provider.
        locale (Union[Unset, str]): The locale of the video Example: fr-FR.
        source_number (Union[Unset, int]): Unique identifier for the video source. This is unique for the
            provider/fixtureId/locale combination.  Unless the provider is supplying multiple sources per fixture/locale
            then this is normally 1. Default: 1. Example: 1.
        feed_type (Union[Unset, VideoStreamInputsModelFeedType]): Type of video input
            >- `ADDITIONAL_ANGLE` Additional angle
            >- `LOW_LATENCY` Low Latency
            >- `PRIMARY` Primary
             Example: PRIMARY.
        input_resolution (Union[Unset, VideoStreamInputsModelInputResolution]): The resolution of the video input
            >- `1080` 1920 x 1080
            >- `288` 512 x 288
            >- `720` 1280 x 720
             Example: 720.
        fps (Union[Unset, int]): fps for the video stream Default: 25. Example: 25.
        name (Union[Unset, str]): The name of the video source
        audio_ambience_channel (Union[Unset, VideoStreamInputsModelAudioAmbienceChannel]): audioAmbienceChannel
            >- `CHANNEL_BOTH` Both channels
            >- `CHANNEL_LEFT` Channel left
            >- `CHANNEL_RIGHT` Channel right
            >- `NONE` None
             Example: CHANNEL_BOTH.
        audio_commentary_channel (Union[Unset, VideoStreamInputsModelAudioCommentaryChannel]): audioCommentaryChannel
            >- `CHANNEL_BOTH` Both channels
            >- `CHANNEL_LEFT` Channel left
            >- `CHANNEL_RIGHT` Channel right
            >- `NONE` None
             Example: CHANNEL_BOTH.
        platform_provider_override (Union[None, Unset, str]): Override Video Provider configuration Example: LOCAL.
        input_url (Union[Unset, str]): The URL where the video should be sent Example:
            rtmp://1ejcn5c-4wmytr5.vi.atriumsports.com/inputin1/inputin1.
        stream_name (Union[Unset, str]): The name/stream key of the RTMP stream. This is an optional part of the RTMP
            url - not a text description.
        updated (Union[Unset, datetime.datetime]): Date/time last modified. In UTC
        added (Union[Unset, datetime.datetime]): Date/time added. In UTC
    """

    video_input_id: Union[Unset, UUID] = UNSET
    master_venue_id: Union[Unset, UUID] = UNSET
    organization_id: Union[Unset, str] = UNSET
    organization: Union[Unset, "VideoStreamInputsModelOrganization"] = UNSET
    venue_id: Union[Unset, UUID] = UNSET
    venue: Union[Unset, "VideoStreamInputsModelVenue"] = UNSET
    competition_id: Union[Unset, UUID] = UNSET
    competition: Union[Unset, "VideoStreamInputsModelCompetition"] = UNSET
    fixture_id: Union[Unset, UUID] = UNSET
    fixture: Union[Unset, "VideoStreamInputsModelFixture"] = UNSET
    start_time_local: Union[Unset, datetime.datetime] = UNSET
    start_time_utc: Union[Unset, datetime.datetime] = UNSET
    finish_recording_time_utc: Union[Unset, datetime.datetime] = UNSET
    estimated_finish_time_utc: Union[Unset, datetime.datetime] = UNSET
    provider: Union[Unset, str] = UNSET
    locale: Union[Unset, str] = UNSET
    source_number: Union[Unset, int] = 1
    feed_type: Union[Unset, VideoStreamInputsModelFeedType] = UNSET
    input_resolution: Union[Unset, VideoStreamInputsModelInputResolution] = UNSET
    fps: Union[Unset, int] = 25
    name: Union[Unset, str] = UNSET
    audio_ambience_channel: Union[Unset, VideoStreamInputsModelAudioAmbienceChannel] = UNSET
    audio_commentary_channel: Union[Unset, VideoStreamInputsModelAudioCommentaryChannel] = UNSET
    platform_provider_override: Union[None, Unset, str] = UNSET
    input_url: Union[Unset, str] = UNSET
    stream_name: Union[Unset, str] = UNSET
    updated: Union[Unset, datetime.datetime] = UNSET
    added: Union[Unset, datetime.datetime] = UNSET

    def to_dict(self) -> dict[str, Any]:
        video_input_id: Union[Unset, str] = UNSET
        if not isinstance(self.video_input_id, Unset):
            video_input_id = str(self.video_input_id)

        master_venue_id: Union[Unset, str] = UNSET
        if not isinstance(self.master_venue_id, Unset):
            master_venue_id = str(self.master_venue_id)

        organization_id = self.organization_id

        organization: Union[Unset, dict[str, Any]] = UNSET
        if not isinstance(self.organization, Unset):
            organization = self.organization.to_dict()

        venue_id: Union[Unset, str] = UNSET
        if not isinstance(self.venue_id, Unset):
            venue_id = str(self.venue_id)

        venue: Union[Unset, dict[str, Any]] = UNSET
        if not isinstance(self.venue, Unset):
            venue = self.venue.to_dict()

        competition_id: Union[Unset, str] = UNSET
        if not isinstance(self.competition_id, Unset):
            competition_id = str(self.competition_id)

        competition: Union[Unset, dict[str, Any]] = UNSET
        if not isinstance(self.competition, Unset):
            competition = self.competition.to_dict()

        fixture_id: Union[Unset, str] = UNSET
        if not isinstance(self.fixture_id, Unset):
            fixture_id = str(self.fixture_id)

        fixture: Union[Unset, dict[str, Any]] = UNSET
        if not isinstance(self.fixture, Unset):
            fixture = self.fixture.to_dict()

        start_time_local: Union[Unset, str] = UNSET
        if not isinstance(self.start_time_local, Unset):
            start_time_local = self.start_time_local.isoformat()

        start_time_utc: Union[Unset, str] = UNSET
        if not isinstance(self.start_time_utc, Unset):
            start_time_utc = self.start_time_utc.isoformat()

        finish_recording_time_utc: Union[Unset, str] = UNSET
        if not isinstance(self.finish_recording_time_utc, Unset):
            finish_recording_time_utc = self.finish_recording_time_utc.isoformat()

        estimated_finish_time_utc: Union[Unset, str] = UNSET
        if not isinstance(self.estimated_finish_time_utc, Unset):
            estimated_finish_time_utc = self.estimated_finish_time_utc.isoformat()

        provider = self.provider

        locale = self.locale

        source_number = self.source_number

        feed_type: Union[Unset, str] = UNSET
        if not isinstance(self.feed_type, Unset):
            feed_type = self.feed_type.value

        input_resolution: Union[Unset, str] = UNSET
        if not isinstance(self.input_resolution, Unset):
            input_resolution = self.input_resolution.value

        fps = self.fps

        name = self.name

        audio_ambience_channel: Union[Unset, str] = UNSET
        if not isinstance(self.audio_ambience_channel, Unset):
            audio_ambience_channel = self.audio_ambience_channel.value

        audio_commentary_channel: Union[Unset, str] = UNSET
        if not isinstance(self.audio_commentary_channel, Unset):
            audio_commentary_channel = self.audio_commentary_channel.value

        platform_provider_override: Union[None, Unset, str]
        if isinstance(self.platform_provider_override, Unset):
            platform_provider_override = UNSET
        else:
            platform_provider_override = self.platform_provider_override

        input_url = self.input_url

        stream_name = self.stream_name

        updated: Union[Unset, str] = UNSET
        if not isinstance(self.updated, Unset):
            updated = self.updated.isoformat()

        added: Union[Unset, str] = UNSET
        if not isinstance(self.added, Unset):
            added = self.added.isoformat()

        field_dict: dict[str, Any] = {}

        field_dict.update({})
        if video_input_id is not UNSET:
            field_dict["videoInputId"] = video_input_id
        if master_venue_id is not UNSET:
            field_dict["masterVenueId"] = master_venue_id
        if organization_id is not UNSET:
            field_dict["organizationId"] = organization_id
        if organization is not UNSET:
            field_dict["organization"] = organization
        if venue_id is not UNSET:
            field_dict["venueId"] = venue_id
        if venue is not UNSET:
            field_dict["venue"] = venue
        if competition_id is not UNSET:
            field_dict["competitionId"] = competition_id
        if competition is not UNSET:
            field_dict["competition"] = competition
        if fixture_id is not UNSET:
            field_dict["fixtureId"] = fixture_id
        if fixture is not UNSET:
            field_dict["fixture"] = fixture
        if start_time_local is not UNSET:
            field_dict["startTimeLocal"] = start_time_local
        if start_time_utc is not UNSET:
            field_dict["startTimeUTC"] = start_time_utc
        if finish_recording_time_utc is not UNSET:
            field_dict["finishRecordingTimeUTC"] = finish_recording_time_utc
        if estimated_finish_time_utc is not UNSET:
            field_dict["estimatedFinishTimeUTC"] = estimated_finish_time_utc
        if provider is not UNSET:
            field_dict["provider"] = provider
        if locale is not UNSET:
            field_dict["locale"] = locale
        if source_number is not UNSET:
            field_dict["sourceNumber"] = source_number
        if feed_type is not UNSET:
            field_dict["feedType"] = feed_type
        if input_resolution is not UNSET:
            field_dict["inputResolution"] = input_resolution
        if fps is not UNSET:
            field_dict["fps"] = fps
        if name is not UNSET:
            field_dict["name"] = name
        if audio_ambience_channel is not UNSET:
            field_dict["audioAmbienceChannel"] = audio_ambience_channel
        if audio_commentary_channel is not UNSET:
            field_dict["audioCommentaryChannel"] = audio_commentary_channel
        if platform_provider_override is not UNSET:
            field_dict["platformProviderOverride"] = platform_provider_override
        if input_url is not UNSET:
            field_dict["inputURL"] = input_url
        if stream_name is not UNSET:
            field_dict["streamName"] = stream_name
        if updated is not UNSET:
            field_dict["updated"] = updated
        if added is not UNSET:
            field_dict["added"] = added

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.video_stream_inputs_model_competition import VideoStreamInputsModelCompetition
        from ..models.video_stream_inputs_model_fixture import VideoStreamInputsModelFixture
        from ..models.video_stream_inputs_model_organization import VideoStreamInputsModelOrganization
        from ..models.video_stream_inputs_model_venue import VideoStreamInputsModelVenue

        d = dict(src_dict)
        _video_input_id = d.pop("videoInputId", UNSET)
        video_input_id: Union[Unset, UUID]
        if isinstance(_video_input_id, Unset):
            video_input_id = UNSET
        else:
            video_input_id = UUID(_video_input_id)

        _master_venue_id = d.pop("masterVenueId", UNSET)
        master_venue_id: Union[Unset, UUID]
        if isinstance(_master_venue_id, Unset):
            master_venue_id = UNSET
        else:
            master_venue_id = UUID(_master_venue_id)

        organization_id = d.pop("organizationId", UNSET)

        _organization = d.pop("organization", UNSET)
        organization: Union[Unset, VideoStreamInputsModelOrganization]
        if isinstance(_organization, Unset):
            organization = UNSET
        else:
            organization = VideoStreamInputsModelOrganization.from_dict(_organization)

        _venue_id = d.pop("venueId", UNSET)
        venue_id: Union[Unset, UUID]
        if isinstance(_venue_id, Unset):
            venue_id = UNSET
        else:
            venue_id = UUID(_venue_id)

        _venue = d.pop("venue", UNSET)
        venue: Union[Unset, VideoStreamInputsModelVenue]
        if isinstance(_venue, Unset):
            venue = UNSET
        else:
            venue = VideoStreamInputsModelVenue.from_dict(_venue)

        _competition_id = d.pop("competitionId", UNSET)
        competition_id: Union[Unset, UUID]
        if isinstance(_competition_id, Unset):
            competition_id = UNSET
        else:
            competition_id = UUID(_competition_id)

        _competition = d.pop("competition", UNSET)
        competition: Union[Unset, VideoStreamInputsModelCompetition]
        if isinstance(_competition, Unset):
            competition = UNSET
        else:
            competition = VideoStreamInputsModelCompetition.from_dict(_competition)

        _fixture_id = d.pop("fixtureId", UNSET)
        fixture_id: Union[Unset, UUID]
        if isinstance(_fixture_id, Unset):
            fixture_id = UNSET
        else:
            fixture_id = UUID(_fixture_id)

        _fixture = d.pop("fixture", UNSET)
        fixture: Union[Unset, VideoStreamInputsModelFixture]
        if isinstance(_fixture, Unset):
            fixture = UNSET
        else:
            fixture = VideoStreamInputsModelFixture.from_dict(_fixture)

        _start_time_local = d.pop("startTimeLocal", UNSET)
        start_time_local: Union[Unset, datetime.datetime]
        if isinstance(_start_time_local, Unset):
            start_time_local = UNSET
        else:
            start_time_local = isoparse(_start_time_local)

        _start_time_utc = d.pop("startTimeUTC", UNSET)
        start_time_utc: Union[Unset, datetime.datetime]
        if isinstance(_start_time_utc, Unset):
            start_time_utc = UNSET
        else:
            start_time_utc = isoparse(_start_time_utc)

        _finish_recording_time_utc = d.pop("finishRecordingTimeUTC", UNSET)
        finish_recording_time_utc: Union[Unset, datetime.datetime]
        if isinstance(_finish_recording_time_utc, Unset):
            finish_recording_time_utc = UNSET
        else:
            finish_recording_time_utc = isoparse(_finish_recording_time_utc)

        _estimated_finish_time_utc = d.pop("estimatedFinishTimeUTC", UNSET)
        estimated_finish_time_utc: Union[Unset, datetime.datetime]
        if isinstance(_estimated_finish_time_utc, Unset):
            estimated_finish_time_utc = UNSET
        else:
            estimated_finish_time_utc = isoparse(_estimated_finish_time_utc)

        provider = d.pop("provider", UNSET)

        locale = d.pop("locale", UNSET)

        source_number = d.pop("sourceNumber", UNSET)

        _feed_type = d.pop("feedType", UNSET)
        feed_type: Union[Unset, VideoStreamInputsModelFeedType]
        if isinstance(_feed_type, Unset):
            feed_type = UNSET
        else:
            feed_type = VideoStreamInputsModelFeedType(_feed_type)

        _input_resolution = d.pop("inputResolution", UNSET)
        input_resolution: Union[Unset, VideoStreamInputsModelInputResolution]
        if isinstance(_input_resolution, Unset):
            input_resolution = UNSET
        else:
            input_resolution = VideoStreamInputsModelInputResolution(_input_resolution)

        fps = d.pop("fps", UNSET)

        name = d.pop("name", UNSET)

        _audio_ambience_channel = d.pop("audioAmbienceChannel", UNSET)
        audio_ambience_channel: Union[Unset, VideoStreamInputsModelAudioAmbienceChannel]
        if isinstance(_audio_ambience_channel, Unset):
            audio_ambience_channel = UNSET
        else:
            audio_ambience_channel = VideoStreamInputsModelAudioAmbienceChannel(_audio_ambience_channel)

        _audio_commentary_channel = d.pop("audioCommentaryChannel", UNSET)
        audio_commentary_channel: Union[Unset, VideoStreamInputsModelAudioCommentaryChannel]
        if isinstance(_audio_commentary_channel, Unset):
            audio_commentary_channel = UNSET
        else:
            audio_commentary_channel = VideoStreamInputsModelAudioCommentaryChannel(_audio_commentary_channel)

        def _parse_platform_provider_override(data: object) -> Union[None, Unset, str]:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(Union[None, Unset, str], data)

        platform_provider_override = _parse_platform_provider_override(d.pop("platformProviderOverride", UNSET))

        input_url = d.pop("inputURL", UNSET)

        stream_name = d.pop("streamName", UNSET)

        _updated = d.pop("updated", UNSET)
        updated: Union[Unset, datetime.datetime]
        if isinstance(_updated, Unset):
            updated = UNSET
        else:
            updated = isoparse(_updated)

        _added = d.pop("added", UNSET)
        added: Union[Unset, datetime.datetime]
        if isinstance(_added, Unset):
            added = UNSET
        else:
            added = isoparse(_added)

        video_stream_inputs_model = cls(
            video_input_id=video_input_id,
            master_venue_id=master_venue_id,
            organization_id=organization_id,
            organization=organization,
            venue_id=venue_id,
            venue=venue,
            competition_id=competition_id,
            competition=competition,
            fixture_id=fixture_id,
            fixture=fixture,
            start_time_local=start_time_local,
            start_time_utc=start_time_utc,
            finish_recording_time_utc=finish_recording_time_utc,
            estimated_finish_time_utc=estimated_finish_time_utc,
            provider=provider,
            locale=locale,
            source_number=source_number,
            feed_type=feed_type,
            input_resolution=input_resolution,
            fps=fps,
            name=name,
            audio_ambience_channel=audio_ambience_channel,
            audio_commentary_channel=audio_commentary_channel,
            platform_provider_override=platform_provider_override,
            input_url=input_url,
            stream_name=stream_name,
            updated=updated,
            added=added,
        )

        return video_stream_inputs_model
