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

from .audit_log_configuration_log_stream import AuditLogConfigurationLogStream
from workos.common.models.audit_log_configuration_state import (
    AuditLogConfigurationState,
)


@dataclass(slots=True)
class AuditLogConfiguration:
    """Audit Log Configuration model."""

    organization_id: str
    """Unique identifier of the Organization."""
    retention_period_in_days: int
    """The number of days Audit Log events will be retained before being permanently deleted."""
    state: "AuditLogConfigurationState"
    """The current state of the audit log configuration for the organization."""
    log_stream: Optional["AuditLogConfigurationLogStream"] = None
    """The Audit Log Stream currently configured for the organization, if any."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "AuditLogConfiguration":
        """Deserialize from a dictionary."""
        try:
            return cls(
                organization_id=data["organization_id"],
                retention_period_in_days=data["retention_period_in_days"],
                state=AuditLogConfigurationState(data["state"]),
                log_stream=AuditLogConfigurationLogStream.from_dict(
                    cast(Dict[str, Any], _v_log_stream)
                )
                if (_v_log_stream := data.get("log_stream")) is not None
                else None,
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("AuditLogConfiguration", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["organization_id"] = self.organization_id
        result["retention_period_in_days"] = self.retention_period_in_days
        result["state"] = (
            self.state.value if isinstance(self.state, Enum) else self.state
        )
        if self.log_stream is not None:
            result["log_stream"] = self.log_stream.to_dict()
        return result
