# coding: utf-8

"""
    Lidarr

    Lidarr API docs

    The version of the OpenAPI document: v2.6.4.4402
    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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, Optional
from lidarr.models.artist_resource import ArtistResource
from lidarr.models.ratings import Ratings
from lidarr.models.track_file_resource import TrackFileResource
from typing import Optional, Set
from typing_extensions import Self

class TrackResource(BaseModel):
    """
    TrackResource
    """ # noqa: E501
    id: Optional[StrictInt] = None
    artist_id: Optional[StrictInt] = Field(default=None, alias="artistId")
    foreign_track_id: Optional[StrictStr] = Field(default=None, alias="foreignTrackId")
    foreign_recording_id: Optional[StrictStr] = Field(default=None, alias="foreignRecordingId")
    track_file_id: Optional[StrictInt] = Field(default=None, alias="trackFileId")
    album_id: Optional[StrictInt] = Field(default=None, alias="albumId")
    explicit: Optional[StrictBool] = None
    absolute_track_number: Optional[StrictInt] = Field(default=None, alias="absoluteTrackNumber")
    track_number: Optional[StrictStr] = Field(default=None, alias="trackNumber")
    title: Optional[StrictStr] = None
    duration: Optional[StrictInt] = None
    track_file: Optional[TrackFileResource] = Field(default=None, alias="trackFile")
    medium_number: Optional[StrictInt] = Field(default=None, alias="mediumNumber")
    has_file: Optional[StrictBool] = Field(default=None, alias="hasFile")
    artist: Optional[ArtistResource] = None
    ratings: Optional[Ratings] = None
    __properties: ClassVar[List[str]] = ["id", "artistId", "foreignTrackId", "foreignRecordingId", "trackFileId", "albumId", "explicit", "absoluteTrackNumber", "trackNumber", "title", "duration", "trackFile", "mediumNumber", "hasFile", "artist", "ratings"]

    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 TrackResource 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 track_file
        if self.track_file:
            _dict['trackFile'] = self.track_file.to_dict()
        # override the default output from pydantic by calling `to_dict()` of artist
        if self.artist:
            _dict['artist'] = self.artist.to_dict()
        # override the default output from pydantic by calling `to_dict()` of ratings
        if self.ratings:
            _dict['ratings'] = self.ratings.to_dict()
        # set to None if foreign_track_id (nullable) is None
        # and model_fields_set contains the field
        if self.foreign_track_id is None and "foreign_track_id" in self.model_fields_set:
            _dict['foreignTrackId'] = None

        # set to None if foreign_recording_id (nullable) is None
        # and model_fields_set contains the field
        if self.foreign_recording_id is None and "foreign_recording_id" in self.model_fields_set:
            _dict['foreignRecordingId'] = None

        # set to None if track_number (nullable) is None
        # and model_fields_set contains the field
        if self.track_number is None and "track_number" in self.model_fields_set:
            _dict['trackNumber'] = None

        # set to None if title (nullable) is None
        # and model_fields_set contains the field
        if self.title is None and "title" in self.model_fields_set:
            _dict['title'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "artistId": obj.get("artistId"),
            "foreignTrackId": obj.get("foreignTrackId"),
            "foreignRecordingId": obj.get("foreignRecordingId"),
            "trackFileId": obj.get("trackFileId"),
            "albumId": obj.get("albumId"),
            "explicit": obj.get("explicit"),
            "absoluteTrackNumber": obj.get("absoluteTrackNumber"),
            "trackNumber": obj.get("trackNumber"),
            "title": obj.get("title"),
            "duration": obj.get("duration"),
            "trackFile": TrackFileResource.from_dict(obj["trackFile"]) if obj.get("trackFile") is not None else None,
            "mediumNumber": obj.get("mediumNumber"),
            "hasFile": obj.get("hasFile"),
            "artist": ArtistResource.from_dict(obj["artist"]) if obj.get("artist") is not None else None,
            "ratings": Ratings.from_dict(obj["ratings"]) if obj.get("ratings") is not None else None
        })
        return _obj


