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

from __future__ import annotations

from dataclasses import dataclass
from typing import Any, Dict, Literal, Optional
from workos._types import _raise_deserialize_error


@dataclass(slots=True)
class AuthenticationPasskeySucceededData:
    """The event payload."""

    type: Literal["passkey"]
    status: Literal["succeeded"]
    ip_address: Optional[str]
    """The IP address of the request."""
    user_agent: Optional[str]
    """The user agent of the request."""
    user_id: str
    """The ID of the user."""
    email: str
    """The email address of the user."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "AuthenticationPasskeySucceededData":
        """Deserialize from a dictionary."""
        try:
            return cls(
                type=data.get("type", "passkey"),
                status=data.get("status", "succeeded"),
                ip_address=data["ip_address"],
                user_agent=data["user_agent"],
                user_id=data["user_id"],
                email=data["email"],
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("AuthenticationPasskeySucceededData", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["type"] = self.type
        result["status"] = self.status
        if self.ip_address is not None:
            result["ip_address"] = self.ip_address
        else:
            result["ip_address"] = None
        if self.user_agent is not None:
            result["user_agent"] = self.user_agent
        else:
            result["user_agent"] = None
        result["user_id"] = self.user_id
        result["email"] = self.email
        return result
