# 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, Literal

from workos._types import _format_datetime, _parse_datetime, _raise_deserialize_error


@dataclass(slots=True)
class EmailVerification:
    """Email Verification model."""

    object: Literal["email_verification"]
    """Distinguishes the email verification object."""
    id: str
    """The unique ID of the email verification code."""
    user_id: str
    """The unique ID of the user."""
    email: str
    """The email address of the user."""
    expires_at: datetime
    """The timestamp when the email verification code expires."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    updated_at: datetime
    """An ISO 8601 timestamp."""
    code: str
    """The code used to verify the email."""

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> EmailVerification:
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "email_verification"),
                id=data["id"],
                user_id=data["user_id"],
                email=data["email"],
                expires_at=_parse_datetime(data["expires_at"]),
                created_at=_parse_datetime(data["created_at"]),
                updated_at=_parse_datetime(data["updated_at"]),
                code=data["code"],
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("EmailVerification", 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["user_id"] = self.user_id
        result["email"] = self.email
        result["expires_at"] = _format_datetime(self.expires_at)
        result["created_at"] = _format_datetime(self.created_at)
        result["updated_at"] = _format_datetime(self.updated_at)
        result["code"] = self.code
        return result
