from __future__ import annotations

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

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_chat_conversation_members import TypesChatConversationMembers
    from ..models.types_chat_message import TypesChatMessage


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


@_attrs_define
class TypesChatConversation:
    """
    Attributes:
        field_id (str | Unset):
        client (str | Unset): Associated with client?
        created_at (str | Unset):
        deleted_at (str | Unset):
        external (list[str] | Unset): Associated with external teams?
        last (TypesChatMessage | Unset):
        members (list[TypesChatConversationMembers] | Unset):
        name (str | Unset):
        team (str | Unset):
        type_ (str | Unset):
        unread (int | Unset): For returning
        updated_at (str | Unset):
    """

    field_id: str | Unset = UNSET
    client: str | Unset = UNSET
    created_at: str | Unset = UNSET
    deleted_at: str | Unset = UNSET
    external: list[str] | Unset = UNSET
    last: TypesChatMessage | Unset = UNSET
    members: list[TypesChatConversationMembers] | Unset = UNSET
    name: str | Unset = UNSET
    team: str | Unset = UNSET
    type_: str | Unset = UNSET
    unread: int | Unset = UNSET
    updated_at: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        field_id = self.field_id

        client = self.client

        created_at = self.created_at

        deleted_at = self.deleted_at

        external: list[str] | Unset = UNSET
        if not isinstance(self.external, Unset):
            external = self.external

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

        members: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.members, Unset):
            members = []
            for members_item_data in self.members:
                members_item = members_item_data.to_dict()
                members.append(members_item)

        name = self.name

        team = self.team

        type_ = self.type_

        unread = self.unread

        updated_at = self.updated_at

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if field_id is not UNSET:
            field_dict["_id"] = field_id
        if client is not UNSET:
            field_dict["client"] = client
        if created_at is not UNSET:
            field_dict["created_at"] = created_at
        if deleted_at is not UNSET:
            field_dict["deleted_at"] = deleted_at
        if external is not UNSET:
            field_dict["external"] = external
        if last is not UNSET:
            field_dict["last"] = last
        if members is not UNSET:
            field_dict["members"] = members
        if name is not UNSET:
            field_dict["name"] = name
        if team is not UNSET:
            field_dict["team"] = team
        if type_ is not UNSET:
            field_dict["type"] = type_
        if unread is not UNSET:
            field_dict["unread"] = unread
        if updated_at is not UNSET:
            field_dict["updated_at"] = updated_at

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.types_chat_conversation_members import TypesChatConversationMembers
        from ..models.types_chat_message import TypesChatMessage

        d = dict(src_dict)
        field_id = d.pop("_id", UNSET)

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

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

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

        external = cast(list[str], d.pop("external", UNSET))

        _last = d.pop("last", UNSET)
        last: TypesChatMessage | Unset
        if isinstance(_last, Unset):
            last = UNSET
        else:
            last = TypesChatMessage.from_dict(_last)

        _members = d.pop("members", UNSET)
        members: list[TypesChatConversationMembers] | Unset = UNSET
        if _members is not UNSET:
            members = []
            for members_item_data in _members:
                members_item = TypesChatConversationMembers.from_dict(members_item_data)

                members.append(members_item)

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

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

        type_ = d.pop("type", UNSET)

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

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

        types_chat_conversation = cls(
            field_id=field_id,
            client=client,
            created_at=created_at,
            deleted_at=deleted_at,
            external=external,
            last=last,
            members=members,
            name=name,
            team=team,
            type_=type_,
            unread=unread,
            updated_at=updated_at,
        )

        types_chat_conversation.additional_properties = d
        return types_chat_conversation

    @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
