import datetime
from collections.abc import Mapping
from typing import (
    Any,
    TypeVar,
    Union,
    cast,
)

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

from ..types import UNSET, Unset

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


@_attrs_define
class PersonResponseDto:
    """
    Attributes:
        birth_date (Union[None, datetime.date]):
        id (str):
        is_hidden (bool):
        name (str):
        thumbnail_path (str):
        color (Union[Unset, str]): This property was added in v1.126.0
        is_favorite (Union[Unset, bool]): This property was added in v1.126.0
        updated_at (Union[Unset, datetime.datetime]): This property was added in v1.107.0
    """

    birth_date: Union[None, datetime.date]
    id: str
    is_hidden: bool
    name: str
    thumbnail_path: str
    color: Union[Unset, str] = UNSET
    is_favorite: Union[Unset, bool] = UNSET
    updated_at: Union[Unset, datetime.datetime] = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        birth_date: Union[None, str]
        if isinstance(self.birth_date, datetime.date):
            birth_date = self.birth_date.isoformat()
        else:
            birth_date = self.birth_date

        id = self.id

        is_hidden = self.is_hidden

        name = self.name

        thumbnail_path = self.thumbnail_path

        color = self.color

        is_favorite = self.is_favorite

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

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "birthDate": birth_date,
                "id": id,
                "isHidden": is_hidden,
                "name": name,
                "thumbnailPath": thumbnail_path,
            }
        )
        if color is not UNSET:
            field_dict["color"] = color
        if is_favorite is not UNSET:
            field_dict["isFavorite"] = is_favorite
        if updated_at is not UNSET:
            field_dict["updatedAt"] = updated_at

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        d = dict(src_dict)

        def _parse_birth_date(data: object) -> Union[None, datetime.date]:
            if data is None:
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                birth_date_type_0 = isoparse(data).date()

                return birth_date_type_0
            except:  # noqa: E722
                pass
            return cast(Union[None, datetime.date], data)

        birth_date = _parse_birth_date(d.pop("birthDate"))

        id = d.pop("id")

        is_hidden = d.pop("isHidden")

        name = d.pop("name")

        thumbnail_path = d.pop("thumbnailPath")

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

        is_favorite = d.pop("isFavorite", UNSET)

        _updated_at = d.pop("updatedAt", UNSET)
        updated_at: Union[Unset, datetime.datetime]
        if isinstance(_updated_at, Unset):
            updated_at = UNSET
        else:
            updated_at = isoparse(_updated_at)

        person_response_dto = cls(
            birth_date=birth_date,
            id=id,
            is_hidden=is_hidden,
            name=name,
            thumbnail_path=thumbnail_path,
            color=color,
            is_favorite=is_favorite,
            updated_at=updated_at,
        )

        person_response_dto.additional_properties = d
        return person_response_dto

    @property
    def additional_keys(self) -> list[str]:
        return list(self.additional_properties.keys())

    def __getitem__(self, key: str) -> Any:
        return self.additional_properties[key]

    def __setitem__(self, key: str, value: Any) -> None:
        self.additional_properties[key] = value

    def __delitem__(self, key: str) -> None:
        del self.additional_properties[key]

    def __contains__(self, key: str) -> bool:
        return key in self.additional_properties
