# 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, List, Optional
from lidarr.models.medium_resource import MediumResource
from typing import Optional, Set
from typing_extensions import Self

class AlbumReleaseResource(BaseModel):
    """
    AlbumReleaseResource
    """ # noqa: E501
    id: Optional[StrictInt] = None
    album_id: Optional[StrictInt] = Field(default=None, alias="albumId")
    foreign_release_id: Optional[StrictStr] = Field(default=None, alias="foreignReleaseId")
    title: Optional[StrictStr] = None
    status: Optional[StrictStr] = None
    duration: Optional[StrictInt] = None
    track_count: Optional[StrictInt] = Field(default=None, alias="trackCount")
    media: Optional[List[MediumResource]] = None
    medium_count: Optional[StrictInt] = Field(default=None, alias="mediumCount")
    disambiguation: Optional[StrictStr] = None
    country: Optional[List[StrictStr]] = None
    label: Optional[List[StrictStr]] = None
    format: Optional[StrictStr] = None
    monitored: Optional[StrictBool] = None
    __properties: ClassVar[List[str]] = ["id", "albumId", "foreignReleaseId", "title", "status", "duration", "trackCount", "media", "mediumCount", "disambiguation", "country", "label", "format", "monitored"]

    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 AlbumReleaseResource 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.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "medium_count",
        ])

        _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 media (list)
        _items = []
        if self.media:
            for _item_media in self.media:
                if _item_media:
                    _items.append(_item_media.to_dict())
            _dict['media'] = _items
        # set to None if foreign_release_id (nullable) is None
        # and model_fields_set contains the field
        if self.foreign_release_id is None and "foreign_release_id" in self.model_fields_set:
            _dict['foreignReleaseId'] = 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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of AlbumReleaseResource 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"),
            "albumId": obj.get("albumId"),
            "foreignReleaseId": obj.get("foreignReleaseId"),
            "title": obj.get("title"),
            "status": obj.get("status"),
            "duration": obj.get("duration"),
            "trackCount": obj.get("trackCount"),
            "media": [MediumResource.from_dict(_item) for _item in obj["media"]] if obj.get("media") is not None else None,
            "mediumCount": obj.get("mediumCount"),
            "disambiguation": obj.get("disambiguation"),
            "country": obj.get("country"),
            "label": obj.get("label"),
            "format": obj.get("format"),
            "monitored": obj.get("monitored")
        })
        return _obj


