# This file is auto-generated by oagen. Do not edit.

from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime
from enum import Enum
from typing import Any, Dict, Optional
from workos._types import _raise_deserialize_error
from workos._types import _format_datetime, _parse_datetime
from workos.common.models.audit_log_configuration_log_stream_state import (
    AuditLogConfigurationLogStreamState,
)
from workos.common.models.audit_log_configuration_log_stream_type import (
    AuditLogConfigurationLogStreamType,
)


@dataclass(slots=True)
class AuditLogConfigurationLogStream:
    """The Audit Log Stream currently configured for the organization, if any."""

    id: str
    """Unique identifier of the Audit Log Stream."""
    type: "AuditLogConfigurationLogStreamType"
    """The type of the Audit Log Stream destination."""
    state: "AuditLogConfigurationLogStreamState"
    """The current state of the Audit Log Stream."""
    last_synced_at: Optional[str]
    """ISO-8601 timestamp of when the last event was successfully synced, or null if no events have been synced."""
    created_at: datetime
    """An ISO 8601 timestamp."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "AuditLogConfigurationLogStream":
        """Deserialize from a dictionary."""
        try:
            return cls(
                id=data["id"],
                type=AuditLogConfigurationLogStreamType(data["type"]),
                state=AuditLogConfigurationLogStreamState(data["state"]),
                last_synced_at=data["last_synced_at"],
                created_at=_parse_datetime(data["created_at"]),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("AuditLogConfigurationLogStream", e)

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