# 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 cast
from typing import Any, Dict
from workos._types import _raise_deserialize_error

from .flag_rule_updated_context_actor import FlagRuleUpdatedContextActor
from .flag_rule_updated_context_configured_target import (
    FlagRuleUpdatedContextConfiguredTarget,
)
from .flag_rule_updated_context_previous_attribute import (
    FlagRuleUpdatedContextPreviousAttribute,
)
from .flag_rule_updated_context_access_type import FlagRuleUpdatedContextAccessType


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

    client_id: str
    """The client ID associated with the flag event."""
    actor: "FlagRuleUpdatedContextActor"
    """The actor who performed the action."""
    access_type: "FlagRuleUpdatedContextAccessType"
    """The access type of the flag rule."""
    configured_targets: "FlagRuleUpdatedContextConfiguredTarget"
    """The configured targets for the flag rule."""
    previous_attributes: "FlagRuleUpdatedContextPreviousAttribute"
    """Attributes that changed from their previous values."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "FlagRuleUpdatedContext":
        """Deserialize from a dictionary."""
        try:
            return cls(
                client_id=data["client_id"],
                actor=FlagRuleUpdatedContextActor.from_dict(
                    cast(Dict[str, Any], data["actor"])
                ),
                access_type=FlagRuleUpdatedContextAccessType(data["access_type"]),
                configured_targets=FlagRuleUpdatedContextConfiguredTarget.from_dict(
                    cast(Dict[str, Any], data["configured_targets"])
                ),
                previous_attributes=FlagRuleUpdatedContextPreviousAttribute.from_dict(
                    cast(Dict[str, Any], data["previous_attributes"])
                ),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("FlagRuleUpdatedContext", 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()
        result["access_type"] = (
            self.access_type.value
            if isinstance(self.access_type, Enum)
            else self.access_type
        )
        result["configured_targets"] = self.configured_targets.to_dict()
        result["previous_attributes"] = self.previous_attributes.to_dict()
        return result
