# 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, Literal, Optional
from workos._types import _raise_deserialize_error
from workos._types import _format_datetime, _parse_datetime
from workos.common.models.audit_log_export_state import AuditLogExportState


@dataclass(slots=True)
class AuditLogExport:
    """Audit Log Export model."""

    object: Literal["audit_log_export"]
    """Distinguishes the Audit Log Export object."""
    id: str
    """The unique ID of the Audit Log Export."""
    state: "AuditLogExportState"
    """The state of the export. Possible values: pending, ready, error, expired."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    updated_at: datetime
    """An ISO 8601 timestamp."""
    url: Optional[str] = None
    """A URL to the CSV file. Only defined when the Audit Log Export is ready."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "AuditLogExport":
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "audit_log_export"),
                id=data["id"],
                state=AuditLogExportState(data["state"]),
                created_at=_parse_datetime(data["created_at"]),
                updated_at=_parse_datetime(data["updated_at"]),
                url=data.get("url"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("AuditLogExport", 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["state"] = (
            self.state.value if isinstance(self.state, Enum) else self.state
        )
        result["created_at"] = _format_datetime(self.created_at)
        result["updated_at"] = _format_datetime(self.updated_at)
        if self.url is not None:
            result["url"] = self.url
        else:
            result["url"] = None
        return result
