# coding: utf-8

"""
    Prowlarr

    Prowlarr API docs

    The version of the OpenAPI document: v1.13.3.4273
    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, Field, StrictBool, StrictInt
from typing import Any, ClassVar, Dict, List, Optional
from prowlarr.models.book_search_param import BookSearchParam
from prowlarr.models.indexer_category import IndexerCategory
from prowlarr.models.movie_search_param import MovieSearchParam
from prowlarr.models.music_search_param import MusicSearchParam
from prowlarr.models.search_param import SearchParam
from prowlarr.models.tv_search_param import TvSearchParam
from typing import Optional, Set
from typing_extensions import Self

class IndexerCapabilityResource(BaseModel):
    """
    IndexerCapabilityResource
    """ # noqa: E501
    id: Optional[StrictInt] = None
    limits_max: Optional[StrictInt] = Field(default=None, alias="limitsMax")
    limits_default: Optional[StrictInt] = Field(default=None, alias="limitsDefault")
    categories: Optional[List[IndexerCategory]] = None
    supports_raw_search: Optional[StrictBool] = Field(default=None, alias="supportsRawSearch")
    search_params: Optional[List[SearchParam]] = Field(default=None, alias="searchParams")
    tv_search_params: Optional[List[TvSearchParam]] = Field(default=None, alias="tvSearchParams")
    movie_search_params: Optional[List[MovieSearchParam]] = Field(default=None, alias="movieSearchParams")
    music_search_params: Optional[List[MusicSearchParam]] = Field(default=None, alias="musicSearchParams")
    book_search_params: Optional[List[BookSearchParam]] = Field(default=None, alias="bookSearchParams")
    __properties: ClassVar[List[str]] = ["id", "limitsMax", "limitsDefault", "categories", "supportsRawSearch", "searchParams", "tvSearchParams", "movieSearchParams", "musicSearchParams", "bookSearchParams"]

    model_config = {
        "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 IndexerCapabilityResource 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 categories (list)
        _items = []
        if self.categories:
            for _item in self.categories:
                if _item:
                    _items.append(_item.to_dict())
            _dict['categories'] = _items
        # set to None if limits_max (nullable) is None
        # and model_fields_set contains the field
        if self.limits_max is None and "limits_max" in self.model_fields_set:
            _dict['limitsMax'] = None

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of IndexerCapabilityResource 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"),
            "limitsMax": obj.get("limitsMax"),
            "limitsDefault": obj.get("limitsDefault"),
            "categories": [IndexerCategory.from_dict(_item) for _item in obj["categories"]] if obj.get("categories") is not None else None,
            "supportsRawSearch": obj.get("supportsRawSearch"),
            "searchParams": obj.get("searchParams"),
            "tvSearchParams": obj.get("tvSearchParams"),
            "movieSearchParams": obj.get("movieSearchParams"),
            "musicSearchParams": obj.get("musicSearchParams"),
            "bookSearchParams": obj.get("bookSearchParams")
        })
        return _obj


