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

from __future__ import annotations

from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, Optional
from workos._types import _raise_deserialize_error
from .authentication_radar_risk_detected_data_action import (
    AuthenticationRadarRiskDetectedDataAction,
)


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

    auth_method: str
    """The authentication method used."""
    action: "AuthenticationRadarRiskDetectedDataAction"
    control: Optional[str]
    """The control action taken for the detected risk."""
    blocklist_type: Optional[str]
    """The type of blocklist that triggered the risk detection."""
    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]) -> "AuthenticationRadarRiskDetectedData":
        """Deserialize from a dictionary."""
        try:
            return cls(
                auth_method=data["auth_method"],
                action=AuthenticationRadarRiskDetectedDataAction(data["action"]),
                control=data["control"],
                blocklist_type=data["blocklist_type"],
                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("AuthenticationRadarRiskDetectedData", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["auth_method"] = self.auth_method
        result["action"] = (
            self.action.value if isinstance(self.action, Enum) else self.action
        )
        if self.control is not None:
            result["control"] = self.control
        else:
            result["control"] = None
        if self.blocklist_type is not None:
            result["blocklist_type"] = self.blocklist_type
        else:
            result["blocklist_type"] = None
        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
