# This file is auto-generated by oagen. Do not edit.

from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime
from typing import cast
from typing import Any, Dict, Literal, Optional
from workos._types import _raise_deserialize_error
from workos._types import _format_datetime, _parse_datetime

from .event_context import EventContext
from .organization_role_deleted_data import OrganizationRoleDeletedData


@dataclass(slots=True)
class OrganizationRoleDeleted:
    """Organization Role Deleted model."""

    object: Literal["event"]
    """Distinguishes the Event object."""
    id: str
    """Unique identifier for the event."""
    event: Literal["organization_role.deleted"]
    data: "OrganizationRoleDeletedData"
    """The event payload."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    context: Optional["EventContext"] = None

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "OrganizationRoleDeleted":
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "event"),
                id=data["id"],
                event=data.get("event", "organization_role.deleted"),
                data=OrganizationRoleDeletedData.from_dict(
                    cast(Dict[str, Any], data["data"])
                ),
                created_at=_parse_datetime(data["created_at"]),
                context=EventContext.from_dict(cast(Dict[str, Any], _v_context))
                if (_v_context := data.get("context")) is not None
                else None,
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("OrganizationRoleDeleted", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["object"] = self.object
        result["id"] = self.id
        result["event"] = self.event
        result["data"] = self.data.to_dict()
        result["created_at"] = _format_datetime(self.created_at)
        if self.context is not None:
            result["context"] = self.context.to_dict()
        return result
