from __future__ import annotations

from collections.abc import Mapping
from typing import Any, TypeVar, BinaryIO, TextIO, TYPE_CHECKING, Generator

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..types import UNSET, Unset

from ..types import UNSET, Unset
from dateutil.parser import isoparse
from typing import cast
import datetime

if TYPE_CHECKING:
  from ..models.api_response_event_response_data_config_type_0 import ApiResponseEventResponseDataConfigType0
  from ..models.api_response_event_response_data_payload import ApiResponseEventResponseDataPayload





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



@_attrs_define
class ApiResponseEventResponseData:
    """ Full event response with all details

        Attributes:
            config (ApiResponseEventResponseDataConfigType0 | None): Event configuration
            created (datetime.datetime): Creation timestamp Example: 2024-01-13T10:30:00Z.
            id (int):
            payload (ApiResponseEventResponseDataPayload): Event payload data
            trigger_ref (str): Trigger reference Example: core.webhook.
            updated (datetime.datetime): Last update timestamp Example: 2024-01-13T10:30:00Z.
            source (int | None | Unset):
            source_ref (None | str | Unset): Source reference Example: monitoring.webhook_sensor.
            trigger (int | None | Unset):
     """

    config: ApiResponseEventResponseDataConfigType0 | None
    created: datetime.datetime
    id: int
    payload: ApiResponseEventResponseDataPayload
    trigger_ref: str
    updated: datetime.datetime
    source: int | None | Unset = UNSET
    source_ref: None | str | Unset = UNSET
    trigger: int | None | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)





    def to_dict(self) -> dict[str, Any]:
        from ..models.api_response_event_response_data_payload import ApiResponseEventResponseDataPayload
        from ..models.api_response_event_response_data_config_type_0 import ApiResponseEventResponseDataConfigType0
        config: dict[str, Any] | None
        if isinstance(self.config, ApiResponseEventResponseDataConfigType0):
            config = self.config.to_dict()
        else:
            config = self.config

        created = self.created.isoformat()

        id = self.id

        payload = self.payload.to_dict()

        trigger_ref = self.trigger_ref

        updated = self.updated.isoformat()

        source: int | None | Unset
        if isinstance(self.source, Unset):
            source = UNSET
        else:
            source = self.source

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

        trigger: int | None | Unset
        if isinstance(self.trigger, Unset):
            trigger = UNSET
        else:
            trigger = self.trigger


        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({
            "config": config,
            "created": created,
            "id": id,
            "payload": payload,
            "trigger_ref": trigger_ref,
            "updated": updated,
        })
        if source is not UNSET:
            field_dict["source"] = source
        if source_ref is not UNSET:
            field_dict["source_ref"] = source_ref
        if trigger is not UNSET:
            field_dict["trigger"] = trigger

        return field_dict



    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.api_response_event_response_data_config_type_0 import ApiResponseEventResponseDataConfigType0
        from ..models.api_response_event_response_data_payload import ApiResponseEventResponseDataPayload
        d = dict(src_dict)
        def _parse_config(data: object) -> ApiResponseEventResponseDataConfigType0 | None:
            if data is None:
                return data
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                config_type_0 = ApiResponseEventResponseDataConfigType0.from_dict(data)



                return config_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(ApiResponseEventResponseDataConfigType0 | None, data)

        config = _parse_config(d.pop("config"))


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




        id = d.pop("id")

        payload = ApiResponseEventResponseDataPayload.from_dict(d.pop("payload"))




        trigger_ref = d.pop("trigger_ref")

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




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

        source = _parse_source(d.pop("source", UNSET))


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

        source_ref = _parse_source_ref(d.pop("source_ref", UNSET))


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

        trigger = _parse_trigger(d.pop("trigger", UNSET))


        api_response_event_response_data = cls(
            config=config,
            created=created,
            id=id,
            payload=payload,
            trigger_ref=trigger_ref,
            updated=updated,
            source=source,
            source_ref=source_ref,
            trigger=trigger,
        )


        api_response_event_response_data.additional_properties = d
        return api_response_event_response_data

    @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
