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

from __future__ import annotations

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

from workos.common.models.authentication_challenge import AuthenticationChallenge


@dataclass(slots=True)
class AuthenticationChallengeVerifyResponse:
    """Authentication Challenge Verify Response model."""

    challenge: "AuthenticationChallenge"
    """The authentication challenge object."""
    valid: bool
    """Whether the code was valid."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "AuthenticationChallengeVerifyResponse":
        """Deserialize from a dictionary."""
        try:
            return cls(
                challenge=AuthenticationChallenge.from_dict(
                    cast(Dict[str, Any], data["challenge"])
                ),
                valid=data["valid"],
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("AuthenticationChallengeVerifyResponse", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["challenge"] = self.challenge.to_dict()
        result["valid"] = self.valid
        return result
