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

from __future__ import annotations

from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, Optional
from workos._types import _raise_deserialize_error
from .event_context_actor_source import EventContextActorSource


@dataclass(slots=True)
class EventContextActor:
    """The actor who performed the action."""

    id: str
    """Unique identifier of the actor."""
    source: "EventContextActorSource"
    """The source of the actor that performed the action."""
    name: Optional[str]
    """The name of the actor."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "EventContextActor":
        """Deserialize from a dictionary."""
        try:
            return cls(
                id=data["id"],
                source=EventContextActorSource(data["source"]),
                name=data["name"],
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("EventContextActor", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["id"] = self.id
        result["source"] = (
            self.source.value if isinstance(self.source, Enum) else self.source
        )
        if self.name is not None:
            result["name"] = self.name
        else:
            result["name"] = None
        return result
