from __future__ import annotations

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

from attrs import define as _attrs_define
from attrs import field as _attrs_field
from dateutil.parser import isoparse

from ..types import UNSET, Unset

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


@_attrs_define
class TimeEvent:
    """
    Attributes:
        event (str | Unset):
        stamp (datetime.datetime | Unset):
        user (str | Unset): MongoDB ObjectId
    """

    event: str | Unset = UNSET
    stamp: datetime.datetime | Unset = UNSET
    user: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        stamp: str | Unset = UNSET
        if not isinstance(self.stamp, Unset):
            stamp = self.stamp.isoformat()

        user = self.user

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if event is not UNSET:
            field_dict["event"] = event
        if stamp is not UNSET:
            field_dict["stamp"] = stamp
        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:
        d = dict(src_dict)
        event = d.pop("event", UNSET)

        _stamp = d.pop("stamp", UNSET)
        stamp: datetime.datetime | Unset
        if isinstance(_stamp, Unset):
            stamp = UNSET
        else:
            stamp = isoparse(_stamp)

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

        time_event = cls(
            event=event,
            stamp=stamp,
            user=user,
        )

        time_event.additional_properties = d
        return time_event

    @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
