r"""
    This code was generated by
   ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
    |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
    |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \

    Twilio - Verify
    This is the public Twilio REST API.

    NOTE: This class is auto generated by OpenAPI Generator.
    https://openapi-generator.tech
    Do not edit the class manually.
"""

from datetime import datetime
from typing import Any, Dict, List, Optional
from twilio.base import deserialize, values

from twilio.base.instance_resource import InstanceResource
from twilio.base.list_resource import ListResource
from twilio.base.version import Version


class NewFactorInstance(InstanceResource):

    class CreateNewPasskeysFactorRequest(object):
        """
        :ivar friendly_name:
        :ivar identity:
        :ivar config:
        """

        def __init__(self, payload: Dict[str, Any]):

            self.friendly_name: Optional[str] = payload.get("friendly_name")
            self.identity: Optional[str] = payload.get("identity")
            self.config: Optional[
                NewFactorList.CreateNewPasskeysFactorRequestConfig
            ] = payload.get("config")

        def to_dict(self):
            return {
                "friendly_name": self.friendly_name,
                "identity": self.identity,
                "config": self.config.to_dict() if self.config is not None else None,
            }

    class CreateNewPasskeysFactorRequestConfig(object):
        """
        :ivar relying_party:
        :ivar authenticator_attachment:
        :ivar discoverable_credentials:
        :ivar user_verification:
        """

        def __init__(self, payload: Dict[str, Any]):

            self.relying_party: Optional[
                NewFactorList.CreateNewPasskeysFactorRequestConfigRelyingParty
            ] = payload.get("relying_party")
            self.authenticator_attachment: Optional["NewFactorInstance.str"] = (
                payload.get("authenticator_attachment")
            )
            self.discoverable_credentials: Optional["NewFactorInstance.str"] = (
                payload.get("discoverable_credentials")
            )
            self.user_verification: Optional["NewFactorInstance.str"] = payload.get(
                "user_verification"
            )

        def to_dict(self):
            return {
                "relying_party": (
                    self.relying_party.to_dict()
                    if self.relying_party is not None
                    else None
                ),
                "authenticator_attachment": self.authenticator_attachment,
                "discoverable_credentials": self.discoverable_credentials,
                "user_verification": self.user_verification,
            }

    class CreateNewPasskeysFactorRequestConfigRelyingParty(object):
        """
        :ivar id:
        :ivar name:
        :ivar origins:
        """

        def __init__(self, payload: Dict[str, Any]):

            self.id: Optional[str] = payload.get("id")
            self.name: Optional[str] = payload.get("name")
            self.origins: Optional[List[str]] = payload.get("origins")

        def to_dict(self):
            return {
                "id": self.id,
                "name": self.name,
                "origins": self.origins,
            }

    """
    :ivar sid: A 34 character string that uniquely identifies this Factor.
    :ivar account_sid: The unique SID identifier of the Account.
    :ivar service_sid: The unique SID identifier of the Service.
    :ivar entity_sid: The unique SID identifier of the Entity.
    :ivar identity: Customer unique identity for the Entity owner of the Factor.
    :ivar binding: Contains the `factor_type` specific secret and metadata. The Binding property is ONLY returned upon Factor creation.
    :ivar options: 
    :ivar date_created: The date that this Factor was created, given in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
    :ivar date_updated: The date that this Factor was updated, given in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
    :ivar friendly_name: The friendly name of this Factor. This can be any string up to 64 characters, meant for humans to distinguish between Factors.
    :ivar status: The Status of this Factor. One of `unverified` or `verified`.
    :ivar factor_type: The Type of this Factor. Currently `push` and `totp` are supported.
    :ivar config: An object that contains configurations specific to a `factor_type`.
    :ivar metadata: Custom metadata associated with the factor.
    :ivar url: The URL of this resource.
    """

    def __init__(self, version: Version, payload: Dict[str, Any], service_sid: str):
        super().__init__(version)

        self.sid: Optional[str] = payload.get("sid")
        self.account_sid: Optional[str] = payload.get("account_sid")
        self.service_sid: Optional[str] = payload.get("service_sid")
        self.entity_sid: Optional[str] = payload.get("entity_sid")
        self.identity: Optional[str] = payload.get("identity")
        self.binding: Optional[Dict[str, object]] = payload.get("binding")
        self.options: Optional[Dict[str, object]] = payload.get("options")
        self.date_created: Optional[datetime] = deserialize.iso8601_datetime(
            payload.get("date_created")
        )
        self.date_updated: Optional[datetime] = deserialize.iso8601_datetime(
            payload.get("date_updated")
        )
        self.friendly_name: Optional[str] = payload.get("friendly_name")
        self.status: Optional[str] = payload.get("status")
        self.factor_type: Optional[str] = payload.get("factor_type")
        self.config: Optional[Dict[str, object]] = payload.get("config")
        self.metadata: Optional[Dict[str, object]] = payload.get("metadata")
        self.url: Optional[str] = payload.get("url")

        self._solution = {
            "service_sid": service_sid,
        }

    def __repr__(self) -> str:
        """
        Provide a friendly representation

        :returns: Machine friendly representation
        """
        context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
        return "<Twilio.Verify.V2.NewFactorInstance {}>".format(context)


class NewFactorList(ListResource):

    class CreateNewPasskeysFactorRequest(object):
        """
        :ivar friendly_name:
        :ivar identity:
        :ivar config:
        """

        def __init__(self, payload: Dict[str, Any]):

            self.friendly_name: Optional[str] = payload.get("friendly_name")
            self.identity: Optional[str] = payload.get("identity")
            self.config: Optional[
                NewFactorList.CreateNewPasskeysFactorRequestConfig
            ] = payload.get("config")

        def to_dict(self):
            return {
                "friendly_name": self.friendly_name,
                "identity": self.identity,
                "config": self.config.to_dict() if self.config is not None else None,
            }

    class CreateNewPasskeysFactorRequestConfig(object):
        """
        :ivar relying_party:
        :ivar authenticator_attachment:
        :ivar discoverable_credentials:
        :ivar user_verification:
        """

        def __init__(self, payload: Dict[str, Any]):

            self.relying_party: Optional[
                NewFactorList.CreateNewPasskeysFactorRequestConfigRelyingParty
            ] = payload.get("relying_party")
            self.authenticator_attachment: Optional["NewFactorInstance.str"] = (
                payload.get("authenticator_attachment")
            )
            self.discoverable_credentials: Optional["NewFactorInstance.str"] = (
                payload.get("discoverable_credentials")
            )
            self.user_verification: Optional["NewFactorInstance.str"] = payload.get(
                "user_verification"
            )

        def to_dict(self):
            return {
                "relying_party": (
                    self.relying_party.to_dict()
                    if self.relying_party is not None
                    else None
                ),
                "authenticator_attachment": self.authenticator_attachment,
                "discoverable_credentials": self.discoverable_credentials,
                "user_verification": self.user_verification,
            }

    class CreateNewPasskeysFactorRequestConfigRelyingParty(object):
        """
        :ivar id:
        :ivar name:
        :ivar origins:
        """

        def __init__(self, payload: Dict[str, Any]):

            self.id: Optional[str] = payload.get("id")
            self.name: Optional[str] = payload.get("name")
            self.origins: Optional[List[str]] = payload.get("origins")

        def to_dict(self):
            return {
                "id": self.id,
                "name": self.name,
                "origins": self.origins,
            }

    def __init__(self, version: Version, service_sid: str):
        """
        Initialize the NewFactorList

        :param version: Version that contains the resource
        :param service_sid: The unique SID identifier of the Service.

        """
        super().__init__(version)

        # Path Solution
        self._solution = {
            "service_sid": service_sid,
        }
        self._uri = "/Services/{service_sid}/Passkeys/Factors".format(**self._solution)

    def create(
        self, create_new_passkeys_factor_request: CreateNewPasskeysFactorRequest
    ) -> NewFactorInstance:
        """
        Create the NewFactorInstance

        :param create_new_passkeys_factor_request:

        :returns: The created NewFactorInstance
        """
        data = create_new_passkeys_factor_request.to_dict()

        headers = values.of({"Content-Type": "application/x-www-form-urlencoded"})

        headers["Content-Type"] = "application/json"

        headers["Accept"] = "application/json"

        payload = self._version.create(
            method="POST", uri=self._uri, data=data, headers=headers
        )

        return NewFactorInstance(
            self._version, payload, service_sid=self._solution["service_sid"]
        )

    async def create_async(
        self, create_new_passkeys_factor_request: CreateNewPasskeysFactorRequest
    ) -> NewFactorInstance:
        """
        Asynchronously create the NewFactorInstance

        :param create_new_passkeys_factor_request:

        :returns: The created NewFactorInstance
        """
        data = create_new_passkeys_factor_request.to_dict()

        headers = values.of({"Content-Type": "application/x-www-form-urlencoded"})

        headers["Content-Type"] = "application/json"

        headers["Accept"] = "application/json"

        payload = await self._version.create_async(
            method="POST", uri=self._uri, data=data, headers=headers
        )

        return NewFactorInstance(
            self._version, payload, service_sid=self._solution["service_sid"]
        )

    def __repr__(self) -> str:
        """
        Provide a friendly representation

        :returns: Machine friendly representation
        """
        return "<Twilio.Verify.V2.NewFactorList>"
