# coding: utf-8

"""
Perigon API

The Perigon API provides access to comprehensive news and web content data. To use the API, simply sign up for a Perigon Business Solutions account to obtain your API key. Your available features may vary based on your plan. See the Authentication section for details on how to use your API key.

The version of the OpenAPI document: 1.0.0
Contact: data@perigon.io
Generated by OpenAPI Generator (https://openapi-generator.tech)

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


from __future__ import annotations

import json
import pprint
import re  # noqa: F401
from typing import Any, ClassVar, Dict, List, Optional, Set

from pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing_extensions import Self

from perigon.models.image_holder import ImageHolder
from perigon.models.wikidata_date_holder import WikidataDateHolder
from perigon.models.wikidata_label_holder import WikidataLabelHolder
from perigon.models.wikidata_political_party_holder import WikidataPoliticalPartyHolder
from perigon.models.wikidata_position_holder import WikidataPositionHolder


class Person(BaseModel):
    """
    Person
    """  # noqa: E501

    wikidata_id: Optional[StrictStr] = Field(default=None, alias="wikidataId")
    created_at: Optional[StrictStr] = Field(default=None, alias="createdAt")
    updated_at: Optional[StrictStr] = Field(default=None, alias="updatedAt")
    name: Optional[StrictStr] = None
    gender: Optional[WikidataLabelHolder] = None
    date_of_birth: Optional[WikidataDateHolder] = Field(
        default=None, alias="dateOfBirth"
    )
    date_of_death: Optional[WikidataDateHolder] = Field(
        default=None, alias="dateOfDeath"
    )
    description: Optional[StrictStr] = None
    aliases: Optional[List[StrictStr]] = None
    occupation: Optional[List[WikidataLabelHolder]] = None
    position: Optional[List[WikidataPositionHolder]] = None
    political_party: Optional[List[WikidataPoliticalPartyHolder]] = Field(
        default=None, alias="politicalParty"
    )
    image: Optional[ImageHolder] = None
    abstract: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = [
        "wikidataId",
        "createdAt",
        "updatedAt",
        "name",
        "gender",
        "dateOfBirth",
        "dateOfDeath",
        "description",
        "aliases",
        "occupation",
        "position",
        "politicalParty",
        "image",
        "abstract",
    ]

    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 Person 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 gender
        if self.gender:
            _dict["gender"] = self.gender.to_dict()
        # override the default output from pydantic by calling `to_dict()` of date_of_birth
        if self.date_of_birth:
            _dict["dateOfBirth"] = self.date_of_birth.to_dict()
        # override the default output from pydantic by calling `to_dict()` of date_of_death
        if self.date_of_death:
            _dict["dateOfDeath"] = self.date_of_death.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in occupation (list)
        _items = []
        if self.occupation:
            for _item_occupation in self.occupation:
                if _item_occupation:
                    _items.append(_item_occupation.to_dict())
            _dict["occupation"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in position (list)
        _items = []
        if self.position:
            for _item_position in self.position:
                if _item_position:
                    _items.append(_item_position.to_dict())
            _dict["position"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in political_party (list)
        _items = []
        if self.political_party:
            for _item_political_party in self.political_party:
                if _item_political_party:
                    _items.append(_item_political_party.to_dict())
            _dict["politicalParty"] = _items
        # override the default output from pydantic by calling `to_dict()` of image
        if self.image:
            _dict["image"] = self.image.to_dict()
        # set to None if wikidata_id (nullable) is None
        # and model_fields_set contains the field
        if self.wikidata_id is None and "wikidata_id" in self.model_fields_set:
            _dict["wikidataId"] = None

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "wikidataId": obj.get("wikidataId"),
                "createdAt": obj.get("createdAt"),
                "updatedAt": obj.get("updatedAt"),
                "name": obj.get("name"),
                "gender": (
                    WikidataLabelHolder.from_dict(obj["gender"])
                    if obj.get("gender") is not None
                    else None
                ),
                "dateOfBirth": (
                    WikidataDateHolder.from_dict(obj["dateOfBirth"])
                    if obj.get("dateOfBirth") is not None
                    else None
                ),
                "dateOfDeath": (
                    WikidataDateHolder.from_dict(obj["dateOfDeath"])
                    if obj.get("dateOfDeath") is not None
                    else None
                ),
                "description": obj.get("description"),
                "aliases": obj.get("aliases"),
                "occupation": (
                    [
                        WikidataLabelHolder.from_dict(_item)
                        for _item in obj["occupation"]
                    ]
                    if obj.get("occupation") is not None
                    else None
                ),
                "position": (
                    [
                        WikidataPositionHolder.from_dict(_item)
                        for _item in obj["position"]
                    ]
                    if obj.get("position") is not None
                    else None
                ),
                "politicalParty": (
                    [
                        WikidataPoliticalPartyHolder.from_dict(_item)
                        for _item in obj["politicalParty"]
                    ]
                    if obj.get("politicalParty") is not None
                    else None
                ),
                "image": (
                    ImageHolder.from_dict(obj["image"])
                    if obj.get("image") is not None
                    else None
                ),
                "abstract": obj.get("abstract"),
            }
        )
        return _obj
