# TODO - remove this special case when we fix the generated code for empty openapi structs
import datetime
from typing import Any, Dict, List, Type, TypeVar, Union

import attr
from dateutil.parser import isoparse

from ..types import UNSET, Unset

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


@attr.s(auto_attribs=True)
class EventOut:
    """
    Attributes:
        payload (str):
        timestamp (datetime.datetime):
        event_type (Union[Unset, None, str]): The event type's name Example: user.signup.
    """

    payload: str
    timestamp: datetime.datetime
    event_type: Union[Unset, None, str] = UNSET
    additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

    def to_dict(self) -> Dict[str, Any]:
        payload = self.payload
        timestamp = self.timestamp.isoformat()

        event_type = self.event_type

        field_dict: Dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "payload": payload,
                "timestamp": timestamp,
            }
        )
        if event_type is not UNSET:
            field_dict["eventType"] = event_type

        return field_dict

    @classmethod
    def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
        d = src_dict.copy()
        payload = d.pop("payload")

        timestamp = isoparse(d.pop("timestamp"))

        event_type = d.pop("eventType", UNSET)

        event_out = cls(
            payload=payload,
            timestamp=timestamp,
            event_type=event_type,
        )

        event_out.additional_properties = d
        return event_out

    @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
