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

from __future__ import annotations

from dataclasses import dataclass
from typing import cast
from typing import Any, Dict, Optional
from workos._types import _raise_deserialize_error

from .flag_updated_context_actor import FlagUpdatedContextActor
from .flag_updated_context_previous_attribute import FlagUpdatedContextPreviousAttribute


@dataclass(slots=True)
class FlagUpdatedContext:
    """Additional context about the event."""

    client_id: str
    """The client ID associated with the flag event."""
    actor: "FlagUpdatedContextActor"
    """The actor who performed the action."""
    previous_attributes: Optional["FlagUpdatedContextPreviousAttribute"] = None
    """Attributes that changed from their previous values."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "FlagUpdatedContext":
        """Deserialize from a dictionary."""
        try:
            return cls(
                client_id=data["client_id"],
                actor=FlagUpdatedContextActor.from_dict(
                    cast(Dict[str, Any], data["actor"])
                ),
                previous_attributes=FlagUpdatedContextPreviousAttribute.from_dict(
                    cast(Dict[str, Any], _v_previous_attributes)
                )
                if (_v_previous_attributes := data.get("previous_attributes"))
                is not None
                else None,
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("FlagUpdatedContext", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["client_id"] = self.client_id
        result["actor"] = self.actor.to_dict()
        if self.previous_attributes is not None:
            result["previous_attributes"] = self.previous_attributes.to_dict()
        return result
