# This file is auto-generated by oagen. Do not edit.

from __future__ import annotations

from dataclasses import dataclass
from typing import Any

from workos._types import _raise_deserialize_error


@dataclass(slots=True)
class SendRadarSmsChallenge:
    """Send Radar Sms Challenge model."""

    user_id: str
    """The ID of the user to send the SMS challenge to."""
    pending_authentication_token: str
    """The pending authentication token from a previous authentication attempt that triggered the Radar challenge."""
    phone_number: str
    """The phone number to send the SMS verification code to."""
    ip_address: str | None = None
    """The IP address of the user's request."""
    user_agent: str | None = None
    """The user agent string from the user's request."""

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> SendRadarSmsChallenge:
        """Deserialize from a dictionary."""
        try:
            return cls(
                user_id=data["user_id"],
                pending_authentication_token=data["pending_authentication_token"],
                phone_number=data["phone_number"],
                ip_address=data.get("ip_address"),
                user_agent=data.get("user_agent"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("SendRadarSmsChallenge", e)

    def to_dict(self) -> dict[str, Any]:
        """Serialize to a dictionary."""
        result: dict[str, Any] = {}
        result["user_id"] = self.user_id
        result["pending_authentication_token"] = self.pending_authentication_token
        result["phone_number"] = self.phone_number
        if self.ip_address is not None:
            result["ip_address"] = self.ip_address
        if self.user_agent is not None:
            result["user_agent"] = self.user_agent
        return result
