# 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
from workos._types import _raise_deserialize_error
from workos._types import _format_datetime, _parse_datetime

from .flag_rule_updated_context import FlagRuleUpdatedContext
from .flag_rule_updated_data import FlagRuleUpdatedData


@dataclass(slots=True)
class FlagRuleUpdated:
    """Flag Rule Updated model."""

    object: Literal["event"]
    """Distinguishes the Event object."""
    id: str
    """Unique identifier for the event."""
    event: Literal["flag.rule_updated"]
    data: "FlagRuleUpdatedData"
    """The event payload."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    context: "FlagRuleUpdatedContext"
    """Additional context about the event."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "FlagRuleUpdated":
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "event"),
                id=data["id"],
                event=data.get("event", "flag.rule_updated"),
                data=FlagRuleUpdatedData.from_dict(cast(Dict[str, Any], data["data"])),
                created_at=_parse_datetime(data["created_at"]),
                context=FlagRuleUpdatedContext.from_dict(
                    cast(Dict[str, Any], data["context"])
                ),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("FlagRuleUpdated", 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)
        result["context"] = self.context.to_dict()
        return result
