# coding: utf-8

"""
    Logto API references

    API references for Logto services. To learn more about how to interact with Logto APIs, see [Interact with Management API](https://docs.logto.io/docs/recipes/interact-with-management-api/).

    The version of the OpenAPI document: Cloud
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from py_logto.models.api_interaction_verification_webauthn_registration_post200_response_exclude_credentials_inner import ApiInteractionVerificationWebauthnRegistrationPost200ResponseExcludeCredentialsInner
from py_logto.models.api_interaction_verification_webauthn_registration_post200_response_extensions import ApiInteractionVerificationWebauthnRegistrationPost200ResponseExtensions
from typing import Optional, Set
from typing_extensions import Self

class ApiInteractionVerificationWebauthnAuthenticationPost200Response(BaseModel):
    """
    ApiInteractionVerificationWebauthnAuthenticationPost200Response
    """ # noqa: E501
    challenge: StrictStr
    timeout: Optional[Union[StrictFloat, StrictInt]] = None
    rp_id: Optional[StrictStr] = Field(default=None, alias="rpId")
    allow_credentials: Optional[List[ApiInteractionVerificationWebauthnRegistrationPost200ResponseExcludeCredentialsInner]] = Field(default=None, alias="allowCredentials")
    user_verification: Optional[StrictStr] = Field(default=None, alias="userVerification")
    extensions: Optional[ApiInteractionVerificationWebauthnRegistrationPost200ResponseExtensions] = None
    __properties: ClassVar[List[str]] = ["challenge", "timeout", "rpId", "allowCredentials", "userVerification", "extensions"]

    @field_validator('user_verification')
    def user_verification_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['required', 'preferred', 'discouraged']):
            raise ValueError("must be one of enum values ('required', 'preferred', 'discouraged')")
        return value

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of ApiInteractionVerificationWebauthnAuthenticationPost200Response from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in allow_credentials (list)
        _items = []
        if self.allow_credentials:
            for _item in self.allow_credentials:
                if _item:
                    _items.append(_item.to_dict())
            _dict['allowCredentials'] = _items
        # override the default output from pydantic by calling `to_dict()` of extensions
        if self.extensions:
            _dict['extensions'] = self.extensions.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ApiInteractionVerificationWebauthnAuthenticationPost200Response from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "challenge": obj.get("challenge"),
            "timeout": obj.get("timeout"),
            "rpId": obj.get("rpId"),
            "allowCredentials": [ApiInteractionVerificationWebauthnRegistrationPost200ResponseExcludeCredentialsInner.from_dict(_item) for _item in obj["allowCredentials"]] if obj.get("allowCredentials") is not None else None,
            "userVerification": obj.get("userVerification"),
            "extensions": ApiInteractionVerificationWebauthnRegistrationPost200ResponseExtensions.from_dict(obj["extensions"]) if obj.get("extensions") is not None else None
        })
        return _obj


