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

from __future__ import annotations

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


@dataclass(slots=True)
class EnrollUserAuthenticationFactor:
    """Enroll User Authentication Factor model."""

    type: Literal["totp"]
    """The type of the factor to enroll."""
    totp_issuer: Optional[str] = None
    """Your application or company name displayed in the user's authenticator app."""
    totp_user: Optional[str] = None
    """The user's account name displayed in their authenticator app."""
    totp_secret: Optional[str] = None
    """The Base32-encoded shared secret for TOTP factors. This can be provided when creating the auth factor, otherwise it will be generated. The algorithm used to derive TOTP codes is SHA-1, the code length is 6 digits, and the timestep is 30 seconds – the secret must be compatible with these parameters."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "EnrollUserAuthenticationFactor":
        """Deserialize from a dictionary."""
        try:
            return cls(
                type=data.get("type", "totp"),
                totp_issuer=data.get("totp_issuer"),
                totp_user=data.get("totp_user"),
                totp_secret=data.get("totp_secret"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("EnrollUserAuthenticationFactor", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["type"] = self.type
        if self.totp_issuer is not None:
            result["totp_issuer"] = self.totp_issuer
        if self.totp_user is not None:
            result["totp_user"] = self.totp_user
        if self.totp_secret is not None:
            result["totp_secret"] = self.totp_secret
        return result
