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


@dataclass(slots=True)
class ObjectVersion:
    """A static snapshot of an encrypted object."""

    created_at: datetime
    """Timestamp when the version was created."""
    current_version: bool
    """Whether this is the active version."""
    etag: str
    """Hash of the object value."""
    id: str
    """Unique identifier of the version."""
    size: int
    """Number of bytes of stored data."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "ObjectVersion":
        """Deserialize from a dictionary."""
        try:
            return cls(
                created_at=_parse_datetime(data["created_at"]),
                current_version=data["current_version"],
                etag=data["etag"],
                id=data["id"],
                size=data["size"],
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("ObjectVersion", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["created_at"] = _format_datetime(self.created_at)
        result["current_version"] = self.current_version
        result["etag"] = self.etag
        result["id"] = self.id
        result["size"] = self.size
        return result
