# 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 ApiKeyUpdatedDataPreviousAttribute:
    """Previous API key attributes before the update."""

    expires_at: Optional[datetime]
    """The previous timestamp when the API Key expired. Null means the key did not expire."""

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

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