# 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 CreateMagicCodeAndReturn:
    """Create Magic Code And Return model."""

    email: str
    """The email address to send the magic code to."""
    invitation_token: str | None = None
    """The invitation token to associate with this magic code."""
    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."""
    radar_auth_attempt_id: str | None = None
    """The ID of an existing Radar authentication attempt to associate with this request."""
    signals_id: str | None = None
    """An optional Radar signals ID to correlate client-side signals with this request."""

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> CreateMagicCodeAndReturn:
        """Deserialize from a dictionary."""
        try:
            return cls(
                email=data["email"],
                invitation_token=data.get("invitation_token"),
                ip_address=data.get("ip_address"),
                user_agent=data.get("user_agent"),
                radar_auth_attempt_id=data.get("radar_auth_attempt_id"),
                signals_id=data.get("signals_id"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("CreateMagicCodeAndReturn", e)

    def to_dict(self) -> dict[str, Any]:
        """Serialize to a dictionary."""
        result: dict[str, Any] = {}
        result["email"] = self.email
        if self.invitation_token is not None:
            result["invitation_token"] = self.invitation_token
        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
        if self.radar_auth_attempt_id is not None:
            result["radar_auth_attempt_id"] = self.radar_auth_attempt_id
        if self.signals_id is not None:
            result["signals_id"] = self.signals_id
        return result
