# 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 RadarChallenge:
    """Radar Challenge model."""

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

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> RadarChallenge:
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "radar_challenge"),
                id=data["id"],
                type=data.get("type", "email"),
                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("RadarChallenge", 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["type"] = self.type
        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
