from __future__ import annotations

from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.types_author import TypesAuthor
    from ..models.types_community_thread import TypesCommunityThread
    from ..models.types_community_topic import TypesCommunityTopic


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


@_attrs_define
class PkgRoutesCommunityTopicGetTopicResponse:
    """
    Attributes:
        authors (list[TypesAuthor] | Unset):
        threads (list[TypesCommunityThread] | Unset):
        topic (TypesCommunityTopic | Unset):
    """

    authors: list[TypesAuthor] | Unset = UNSET
    threads: list[TypesCommunityThread] | Unset = UNSET
    topic: TypesCommunityTopic | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        authors: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.authors, Unset):
            authors = []
            for authors_item_data in self.authors:
                authors_item = authors_item_data.to_dict()
                authors.append(authors_item)

        threads: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.threads, Unset):
            threads = []
            for threads_item_data in self.threads:
                threads_item = threads_item_data.to_dict()
                threads.append(threads_item)

        topic: dict[str, Any] | Unset = UNSET
        if not isinstance(self.topic, Unset):
            topic = self.topic.to_dict()

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if authors is not UNSET:
            field_dict["authors"] = authors
        if threads is not UNSET:
            field_dict["threads"] = threads
        if topic is not UNSET:
            field_dict["topic"] = topic

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.types_author import TypesAuthor
        from ..models.types_community_thread import TypesCommunityThread
        from ..models.types_community_topic import TypesCommunityTopic

        d = dict(src_dict)
        _authors = d.pop("authors", UNSET)
        authors: list[TypesAuthor] | Unset = UNSET
        if _authors is not UNSET:
            authors = []
            for authors_item_data in _authors:
                authors_item = TypesAuthor.from_dict(authors_item_data)

                authors.append(authors_item)

        _threads = d.pop("threads", UNSET)
        threads: list[TypesCommunityThread] | Unset = UNSET
        if _threads is not UNSET:
            threads = []
            for threads_item_data in _threads:
                threads_item = TypesCommunityThread.from_dict(threads_item_data)

                threads.append(threads_item)

        _topic = d.pop("topic", UNSET)
        topic: TypesCommunityTopic | Unset
        if isinstance(_topic, Unset):
            topic = UNSET
        else:
            topic = TypesCommunityTopic.from_dict(_topic)

        pkg_routes_community_topic_get_topic_response = cls(
            authors=authors,
            threads=threads,
            topic=topic,
        )

        pkg_routes_community_topic_get_topic_response.additional_properties = d
        return pkg_routes_community_topic_get_topic_response

    @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
