# 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 .audit_log_schema import AuditLogSchema


@dataclass(slots=True)
class AuditLogAction:
    """Audit Log Action model."""

    object: Literal["audit_log_action"]
    """Distinguishes the Audit Log Action object."""
    name: str
    """Identifier of what action was taken."""
    schema: "AuditLogSchema"
    """The schema associated with the action."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    updated_at: datetime
    """An ISO 8601 timestamp."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "AuditLogAction":
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "audit_log_action"),
                name=data["name"],
                schema=AuditLogSchema.from_dict(cast(Dict[str, Any], data["schema"])),
                created_at=_parse_datetime(data["created_at"]),
                updated_at=_parse_datetime(data["updated_at"]),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("AuditLogAction", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["object"] = self.object
        result["name"] = self.name
        result["schema"] = self.schema.to_dict()
        result["created_at"] = _format_datetime(self.created_at)
        result["updated_at"] = _format_datetime(self.updated_at)
        return result
