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


@dataclass(slots=True)
class ObjectSummary:
    """Summary of an encrypted object returned in list responses."""

    id: str
    """Unique identifier of the object."""
    name: str
    """Unique name of the object."""
    updated_at: Optional[datetime] = None
    """Timestamp of the last update."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "ObjectSummary":
        """Deserialize from a dictionary."""
        try:
            return cls(
                id=data["id"],
                name=data["name"],
                updated_at=_parse_datetime(_v_updated_at)
                if (_v_updated_at := data.get("updated_at")) is not None
                else None,
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("ObjectSummary", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["id"] = self.id
        result["name"] = self.name
        if self.updated_at is not None:
            result["updated_at"] = _format_datetime(self.updated_at)
        else:
            result["updated_at"] = None
        return result
