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

from __future__ import annotations

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


@dataclass(slots=True)
class AuthenticationFactorEnrolledTotp:
    """TOTP-based authentication factor details. Includes enrollment secrets only available at creation time."""

    issuer: str
    """Your application or company name displayed in the user's authenticator app. Defaults to your WorkOS team name."""
    user: str
    """The user's account name displayed in their authenticator app. Defaults to the user's email."""
    secret: str
    """TOTP secret that can be manually entered into some authenticator apps in place of scanning a QR code."""
    qr_code: str
    """Base64 encoded image containing scannable QR code."""
    uri: str
    """The `otpauth` URI that is encoded by the provided `qr_code`."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "AuthenticationFactorEnrolledTotp":
        """Deserialize from a dictionary."""
        try:
            return cls(
                issuer=data["issuer"],
                user=data["user"],
                secret=data["secret"],
                qr_code=data["qr_code"],
                uri=data["uri"],
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("AuthenticationFactorEnrolledTotp", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["issuer"] = self.issuer
        result["user"] = self.user
        result["secret"] = self.secret
        result["qr_code"] = self.qr_code
        result["uri"] = self.uri
        return result
