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

from .audit_log_schema_actor_input import AuditLogSchemaActorInput
from .audit_log_schema_target_input import AuditLogSchemaTargetInput


@dataclass(slots=True)
class AuditLogSchemaInput:
    """Audit Log Schema Input model."""

    targets: List["AuditLogSchemaTargetInput"]
    """The list of targets for the schema."""
    actor: Optional["AuditLogSchemaActorInput"] = None
    """The metadata schema for the actor."""
    metadata: Optional[Dict[str, Any]] = None
    """Optional JSON schema for event metadata."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "AuditLogSchemaInput":
        """Deserialize from a dictionary."""
        try:
            return cls(
                targets=[
                    AuditLogSchemaTargetInput.from_dict(cast(Dict[str, Any], item))
                    for item in cast(list[Any], data["targets"])
                ],
                actor=AuditLogSchemaActorInput.from_dict(cast(Dict[str, Any], _v_actor))
                if (_v_actor := data.get("actor")) is not None
                else None,
                metadata=data.get("metadata"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("AuditLogSchemaInput", e)

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