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

from __future__ import annotations

from dataclasses import dataclass
from typing import Any, Literal

from workos._types import _raise_deserialize_error


@dataclass(slots=True)
class MFATotpSessionAuthenticateRequest:
    """MFA Totp Session Authenticate Request model."""

    client_id: str
    """The client ID of the application."""
    client_secret: str
    """The client secret of the application."""
    grant_type: Literal["urn:workos:oauth:grant-type:mfa-totp"]
    code: str
    """The TOTP code from the authenticator app."""
    pending_authentication_token: str
    """The pending authentication token from a previous authentication attempt."""
    authentication_challenge_id: str
    """The ID of the MFA authentication challenge."""
    ip_address: str | None = None
    """The IP address of the user's request."""
    device_id: str | None = None
    """A unique identifier for the device."""
    user_agent: str | None = None
    """The user agent string from the user's browser."""

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> MFATotpSessionAuthenticateRequest:
        """Deserialize from a dictionary."""
        try:
            return cls(
                client_id=data["client_id"],
                client_secret=data["client_secret"],
                grant_type=data.get(
                    "grant_type", "urn:workos:oauth:grant-type:mfa-totp"
                ),
                code=data["code"],
                pending_authentication_token=data["pending_authentication_token"],
                authentication_challenge_id=data["authentication_challenge_id"],
                ip_address=data.get("ip_address"),
                device_id=data.get("device_id"),
                user_agent=data.get("user_agent"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("MFATotpSessionAuthenticateRequest", e)

    def to_dict(self) -> dict[str, Any]:
        """Serialize to a dictionary."""
        result: dict[str, Any] = {}
        result["client_id"] = self.client_id
        result["client_secret"] = self.client_secret
        result["grant_type"] = self.grant_type
        result["code"] = self.code
        result["pending_authentication_token"] = self.pending_authentication_token
        result["authentication_challenge_id"] = self.authentication_challenge_id
        if self.ip_address is not None:
            result["ip_address"] = self.ip_address
        if self.device_id is not None:
            result["device_id"] = self.device_id
        if self.user_agent is not None:
            result["user_agent"] = self.user_agent
        return result
