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_change import TypesChange


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


@_attrs_define
class TypesActivity:
    """
    Attributes:
        field_id (str | Unset):
        action (str | Unset):
        changes (list[TypesChange] | Unset):
        client (str | Unset):
        on_id (str | Unset):
        on_py (int | Unset):
        on_type (str | Unset):
        team (str | Unset):
        timestamp (str | Unset):
        user (str | Unset):
    """

    field_id: str | Unset = UNSET
    action: str | Unset = UNSET
    changes: list[TypesChange] | Unset = UNSET
    client: str | Unset = UNSET
    on_id: str | Unset = UNSET
    on_py: int | Unset = UNSET
    on_type: str | Unset = UNSET
    team: str | Unset = UNSET
    timestamp: str | Unset = UNSET
    user: 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

        action = self.action

        changes: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.changes, Unset):
            changes = []
            for changes_item_data in self.changes:
                changes_item = changes_item_data.to_dict()
                changes.append(changes_item)

        client = self.client

        on_id = self.on_id

        on_py = self.on_py

        on_type = self.on_type

        team = self.team

        timestamp = self.timestamp

        user = self.user

        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 action is not UNSET:
            field_dict["action"] = action
        if changes is not UNSET:
            field_dict["changes"] = changes
        if client is not UNSET:
            field_dict["client"] = client
        if on_id is not UNSET:
            field_dict["on_id"] = on_id
        if on_py is not UNSET:
            field_dict["on_py"] = on_py
        if on_type is not UNSET:
            field_dict["on_type"] = on_type
        if team is not UNSET:
            field_dict["team"] = team
        if timestamp is not UNSET:
            field_dict["timestamp"] = timestamp
        if user is not UNSET:
            field_dict["user"] = user

        return field_dict

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

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

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

        _changes = d.pop("changes", UNSET)
        changes: list[TypesChange] | Unset = UNSET
        if _changes is not UNSET:
            changes = []
            for changes_item_data in _changes:
                changes_item = TypesChange.from_dict(changes_item_data)

                changes.append(changes_item)

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

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

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

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

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

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

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

        types_activity = cls(
            field_id=field_id,
            action=action,
            changes=changes,
            client=client,
            on_id=on_id,
            on_py=on_py,
            on_type=on_type,
            team=team,
            timestamp=timestamp,
            user=user,
        )

        types_activity.additional_properties = d
        return types_activity

    @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
