# 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 workos.common.models.radar_standalone_response_blocklist_type import (
    RadarStandaloneResponseBlocklistType,
)
from workos.common.models.radar_standalone_response_control import (
    RadarStandaloneResponseControl,
)
from workos.common.models.radar_standalone_response_verdict import (
    RadarStandaloneResponseVerdict,
)


@dataclass(slots=True)
class RadarStandaloneResponse:
    """Radar Standalone Response model."""

    verdict: "RadarStandaloneResponseVerdict"
    """The verdict of the risk assessment."""
    reason: str
    """A human-readable reason for the verdict."""
    attempt_id: str
    """Unique identifier of the authentication attempt."""
    control: Optional["RadarStandaloneResponseControl"] = None
    """The Radar control that triggered the verdict. Only present if the verdict is `block` or `challenge`."""
    blocklist_type: Optional["RadarStandaloneResponseBlocklistType"] = None
    """The type of blocklist entry that triggered the verdict. Only present if the control is `restriction`."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "RadarStandaloneResponse":
        """Deserialize from a dictionary."""
        try:
            return cls(
                verdict=RadarStandaloneResponseVerdict(data["verdict"]),
                reason=data["reason"],
                attempt_id=data["attempt_id"],
                control=RadarStandaloneResponseControl(_v_control)
                if (_v_control := data.get("control")) is not None
                else None,
                blocklist_type=RadarStandaloneResponseBlocklistType(_v_blocklist_type)
                if (_v_blocklist_type := data.get("blocklist_type")) is not None
                else None,
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("RadarStandaloneResponse", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["verdict"] = (
            self.verdict.value if isinstance(self.verdict, Enum) else self.verdict
        )
        result["reason"] = self.reason
        result["attempt_id"] = self.attempt_id
        if self.control is not None:
            result["control"] = (
                self.control.value if isinstance(self.control, Enum) else self.control
            )
        if self.blocklist_type is not None:
            result["blocklist_type"] = (
                self.blocklist_type.value
                if isinstance(self.blocklist_type, Enum)
                else self.blocklist_type
            )
        return result
