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="PkgRoutesCommunityTopResponse")


@_attrs_define
class PkgRoutesCommunityTopResponse:
    """
    Attributes:
        authors (list[TypesAuthor] | Unset):
        recent_threads (list[TypesCommunityThread] | Unset):
        resolved_threads (list[TypesCommunityThread] | Unset):
        topics (list[TypesCommunityTopic] | Unset):
        unresolved_threads (list[TypesCommunityThread] | Unset):
    """

    authors: list[TypesAuthor] | Unset = UNSET
    recent_threads: list[TypesCommunityThread] | Unset = UNSET
    resolved_threads: list[TypesCommunityThread] | Unset = UNSET
    topics: list[TypesCommunityTopic] | Unset = UNSET
    unresolved_threads: list[TypesCommunityThread] | 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)

        recent_threads: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.recent_threads, Unset):
            recent_threads = []
            for recent_threads_item_data in self.recent_threads:
                recent_threads_item = recent_threads_item_data.to_dict()
                recent_threads.append(recent_threads_item)

        resolved_threads: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.resolved_threads, Unset):
            resolved_threads = []
            for resolved_threads_item_data in self.resolved_threads:
                resolved_threads_item = resolved_threads_item_data.to_dict()
                resolved_threads.append(resolved_threads_item)

        topics: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.topics, Unset):
            topics = []
            for topics_item_data in self.topics:
                topics_item = topics_item_data.to_dict()
                topics.append(topics_item)

        unresolved_threads: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.unresolved_threads, Unset):
            unresolved_threads = []
            for unresolved_threads_item_data in self.unresolved_threads:
                unresolved_threads_item = unresolved_threads_item_data.to_dict()
                unresolved_threads.append(unresolved_threads_item)

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if authors is not UNSET:
            field_dict["authors"] = authors
        if recent_threads is not UNSET:
            field_dict["recent_threads"] = recent_threads
        if resolved_threads is not UNSET:
            field_dict["resolved_threads"] = resolved_threads
        if topics is not UNSET:
            field_dict["topics"] = topics
        if unresolved_threads is not UNSET:
            field_dict["unresolved_threads"] = unresolved_threads

        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)

        _recent_threads = d.pop("recent_threads", UNSET)
        recent_threads: list[TypesCommunityThread] | Unset = UNSET
        if _recent_threads is not UNSET:
            recent_threads = []
            for recent_threads_item_data in _recent_threads:
                recent_threads_item = TypesCommunityThread.from_dict(recent_threads_item_data)

                recent_threads.append(recent_threads_item)

        _resolved_threads = d.pop("resolved_threads", UNSET)
        resolved_threads: list[TypesCommunityThread] | Unset = UNSET
        if _resolved_threads is not UNSET:
            resolved_threads = []
            for resolved_threads_item_data in _resolved_threads:
                resolved_threads_item = TypesCommunityThread.from_dict(resolved_threads_item_data)

                resolved_threads.append(resolved_threads_item)

        _topics = d.pop("topics", UNSET)
        topics: list[TypesCommunityTopic] | Unset = UNSET
        if _topics is not UNSET:
            topics = []
            for topics_item_data in _topics:
                topics_item = TypesCommunityTopic.from_dict(topics_item_data)

                topics.append(topics_item)

        _unresolved_threads = d.pop("unresolved_threads", UNSET)
        unresolved_threads: list[TypesCommunityThread] | Unset = UNSET
        if _unresolved_threads is not UNSET:
            unresolved_threads = []
            for unresolved_threads_item_data in _unresolved_threads:
                unresolved_threads_item = TypesCommunityThread.from_dict(unresolved_threads_item_data)

                unresolved_threads.append(unresolved_threads_item)

        pkg_routes_community_top_response = cls(
            authors=authors,
            recent_threads=recent_threads,
            resolved_threads=resolved_threads,
            topics=topics,
            unresolved_threads=unresolved_threads,
        )

        pkg_routes_community_top_response.additional_properties = d
        return pkg_routes_community_top_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
