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.message_input_tools import MessageInputTools


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


@_attrs_define
class MessageInput:
    """
    Attributes:
        content (str):
        workspace_ext_id (str):
        tools (MessageInputTools | Unset):
        parent_message_ext_id (None | str | Unset):
        config_ext_id (None | str | Unset):
    """

    content: str
    workspace_ext_id: str
    tools: MessageInputTools | Unset = UNSET
    parent_message_ext_id: None | str | Unset = UNSET
    config_ext_id: None | str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        workspace_ext_id = self.workspace_ext_id

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

        parent_message_ext_id: None | str | Unset
        if isinstance(self.parent_message_ext_id, Unset):
            parent_message_ext_id = UNSET
        else:
            parent_message_ext_id = self.parent_message_ext_id

        config_ext_id: None | str | Unset
        if isinstance(self.config_ext_id, Unset):
            config_ext_id = UNSET
        else:
            config_ext_id = self.config_ext_id

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "content": content,
                "workspace_ext_id": workspace_ext_id,
            }
        )
        if tools is not UNSET:
            field_dict["tools"] = tools
        if parent_message_ext_id is not UNSET:
            field_dict["parent_message_ext_id"] = parent_message_ext_id
        if config_ext_id is not UNSET:
            field_dict["config_ext_id"] = config_ext_id

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.message_input_tools import MessageInputTools

        d = dict(src_dict)
        content = d.pop("content")

        workspace_ext_id = d.pop("workspace_ext_id")

        _tools = d.pop("tools", UNSET)
        tools: MessageInputTools | Unset
        if isinstance(_tools, Unset):
            tools = UNSET
        else:
            tools = MessageInputTools.from_dict(_tools)

        def _parse_parent_message_ext_id(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        parent_message_ext_id = _parse_parent_message_ext_id(d.pop("parent_message_ext_id", UNSET))

        def _parse_config_ext_id(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        config_ext_id = _parse_config_ext_id(d.pop("config_ext_id", UNSET))

        message_input = cls(
            content=content,
            workspace_ext_id=workspace_ext_id,
            tools=tools,
            parent_message_ext_id=parent_message_ext_id,
            config_ext_id=config_ext_id,
        )

        message_input.additional_properties = d
        return message_input

    @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
