# 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.authentication_factors_create_request_type import (
    AuthenticationFactorsCreateRequestType,
)


@dataclass(slots=True)
class AuthenticationFactorsCreateRequest:
    """Authentication Factors Create Request model."""

    type: "AuthenticationFactorsCreateRequestType"
    """The type of factor to enroll."""
    phone_number: Optional[str] = None
    """Required when type is 'sms'."""
    totp_issuer: Optional[str] = None
    """Required when type is 'totp'."""
    totp_user: Optional[str] = None
    """Required when type is 'totp'."""
    user_id: Optional[str] = None
    """The ID of the user to associate the factor with."""

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

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["type"] = self.type.value if isinstance(self.type, Enum) else self.type
        if self.phone_number is not None:
            result["phone_number"] = self.phone_number
        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.user_id is not None:
            result["user_id"] = self.user_id
        return result
