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, 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 ApproveChallengeInstance(InstanceResource):

    class ApprovePasskeysChallengeRequest(object):
        """
        :ivar id: A [base64url](https://base64.guru/standards/base64url) encoded representation of `rawId`.
        :ivar raw_id: The globally unique identifier for this `PublicKeyCredential`.
        :ivar authenticator_attachment: A string that indicates the mechanism by which the WebAuthn implementation is attached to the authenticator at the time the associated `navigator.credentials.create()` or `navigator.credentials.get()` call completes.
        :ivar type: The valid credential types supported by the API. The values of this enumeration are used for versioning the `AuthenticatorAssertion` and `AuthenticatorAttestation` structures according to the type of the authenticator.
        :ivar response:
        """

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

            self.id: Optional[str] = payload.get("id")
            self.raw_id: Optional[str] = payload.get("raw_id")
            self.authenticator_attachment: Optional["ApproveChallengeInstance.str"] = (
                payload.get("authenticator_attachment")
            )
            self.type: Optional["ApproveChallengeInstance.str"] = payload.get("type")
            self.response: Optional[
                ApproveChallengeList.ApprovePasskeysChallengeRequestResponse
            ] = payload.get("response")

        def to_dict(self):
            return {
                "id": self.id,
                "raw_id": self.raw_id,
                "authenticator_attachment": self.authenticator_attachment,
                "type": self.type,
                "response": (
                    self.response.to_dict() if self.response is not None else None
                ),
            }

    class ApprovePasskeysChallengeRequestResponse(object):
        """
        :ivar authenticator_data: The [authenticator data](https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API/Authenticator_data) structure contains information from the authenticator about the processing of a credential creation or authentication request.
        :ivar client_data_json: This property contains the JSON-compatible serialization of the data passed from the browser to the authenticator in order to generate this credential.
        :ivar signature: An assertion signature over `authenticatorData` and `clientDataJSON`. The assertion signature is created with the private key of the key pair that was created during the originating `navigator.credentials.create()` call and verified using the public key of that same key pair.
        :ivar user_handle: The user handle stored in the authenticator, specified as `user.id` in the options passed to the originating `navigator.credentials.create()` call. This property should contain a base64url-encoded entity SID.
        """

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

            self.authenticator_data: Optional[str] = payload.get("authenticator_data")
            self.client_data_json: Optional[str] = payload.get("client_data_json")
            self.signature: Optional[str] = payload.get("signature")
            self.user_handle: Optional[str] = payload.get("user_handle")

        def to_dict(self):
            return {
                "authenticator_data": self.authenticator_data,
                "client_data_json": self.client_data_json,
                "signature": self.signature,
                "user_handle": self.user_handle,
            }

    """
    :ivar options: An object that contains challenge options. Currently only used for `passkeys`.
    :ivar sid: A 34 character string that uniquely identifies this Challenge.
    :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 Challenge.
    :ivar factor_sid: The unique SID identifier of the Factor.
    :ivar date_created: The date that this Challenge was created, given in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
    :ivar date_updated: The date that this Challenge was updated, given in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
    :ivar date_responded: The date that this Challenge was responded, given in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
    :ivar expiration_date: The date-time when this Challenge expires, given in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
    :ivar status: The Status of this Challenge. One of `pending`, `expired`, `approved` or `denied`.
    :ivar responded_reason: Reason for the Challenge to be in certain `status`. One of `none`, `not_needed` or `not_requested`.
    :ivar details: Details provided to give context about the Challenge.
    :ivar hidden_details: Details provided to give context about the Challenge.
    :ivar metadata: Custom metadata associated with the challenge.
    :ivar factor_type: The Factor Type of this Challenge. Currently `push` and `totp` are supported.
    :ivar url: The URL of this resource.
    :ivar links: Contains a dictionary of URL links to nested resources of this Challenge.
    """

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

        self.options: Optional[Dict[str, object]] = payload.get("options")
        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.factor_sid: Optional[str] = payload.get("factor_sid")
        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.date_responded: Optional[datetime] = deserialize.iso8601_datetime(
            payload.get("date_responded")
        )
        self.expiration_date: Optional[datetime] = deserialize.iso8601_datetime(
            payload.get("expiration_date")
        )
        self.status: Optional[str] = payload.get("status")
        self.responded_reason: Optional[str] = payload.get("responded_reason")
        self.details: Optional[Dict[str, object]] = payload.get("details")
        self.hidden_details: Optional[Dict[str, object]] = payload.get("hidden_details")
        self.metadata: Optional[Dict[str, object]] = payload.get("metadata")
        self.factor_type: Optional[str] = payload.get("factor_type")
        self.url: Optional[str] = payload.get("url")
        self.links: Optional[Dict[str, object]] = payload.get("links")

        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.ApproveChallengeInstance {}>".format(context)


class ApproveChallengeList(ListResource):

    class ApprovePasskeysChallengeRequest(object):
        """
        :ivar id: A [base64url](https://base64.guru/standards/base64url) encoded representation of `rawId`.
        :ivar raw_id: The globally unique identifier for this `PublicKeyCredential`.
        :ivar authenticator_attachment: A string that indicates the mechanism by which the WebAuthn implementation is attached to the authenticator at the time the associated `navigator.credentials.create()` or `navigator.credentials.get()` call completes.
        :ivar type: The valid credential types supported by the API. The values of this enumeration are used for versioning the `AuthenticatorAssertion` and `AuthenticatorAttestation` structures according to the type of the authenticator.
        :ivar response:
        """

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

            self.id: Optional[str] = payload.get("id")
            self.raw_id: Optional[str] = payload.get("raw_id")
            self.authenticator_attachment: Optional["ApproveChallengeInstance.str"] = (
                payload.get("authenticator_attachment")
            )
            self.type: Optional["ApproveChallengeInstance.str"] = payload.get("type")
            self.response: Optional[
                ApproveChallengeList.ApprovePasskeysChallengeRequestResponse
            ] = payload.get("response")

        def to_dict(self):
            return {
                "id": self.id,
                "raw_id": self.raw_id,
                "authenticator_attachment": self.authenticator_attachment,
                "type": self.type,
                "response": (
                    self.response.to_dict() if self.response is not None else None
                ),
            }

    class ApprovePasskeysChallengeRequestResponse(object):
        """
        :ivar authenticator_data: The [authenticator data](https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API/Authenticator_data) structure contains information from the authenticator about the processing of a credential creation or authentication request.
        :ivar client_data_json: This property contains the JSON-compatible serialization of the data passed from the browser to the authenticator in order to generate this credential.
        :ivar signature: An assertion signature over `authenticatorData` and `clientDataJSON`. The assertion signature is created with the private key of the key pair that was created during the originating `navigator.credentials.create()` call and verified using the public key of that same key pair.
        :ivar user_handle: The user handle stored in the authenticator, specified as `user.id` in the options passed to the originating `navigator.credentials.create()` call. This property should contain a base64url-encoded entity SID.
        """

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

            self.authenticator_data: Optional[str] = payload.get("authenticator_data")
            self.client_data_json: Optional[str] = payload.get("client_data_json")
            self.signature: Optional[str] = payload.get("signature")
            self.user_handle: Optional[str] = payload.get("user_handle")

        def to_dict(self):
            return {
                "authenticator_data": self.authenticator_data,
                "client_data_json": self.client_data_json,
                "signature": self.signature,
                "user_handle": self.user_handle,
            }

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

        :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/ApproveChallenge".format(
            **self._solution
        )

    def update(
        self, approve_passkeys_challenge_request: ApprovePasskeysChallengeRequest
    ) -> ApproveChallengeInstance:
        """
        Update the ApproveChallengeInstance

        :param approve_passkeys_challenge_request:

        :returns: The created ApproveChallengeInstance
        """
        data = approve_passkeys_challenge_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.update(
            method="POST", uri=self._uri, data=data, headers=headers
        )

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

    async def update_async(
        self, approve_passkeys_challenge_request: ApprovePasskeysChallengeRequest
    ) -> ApproveChallengeInstance:
        """
        Asynchronously update the ApproveChallengeInstance

        :param approve_passkeys_challenge_request:

        :returns: The created ApproveChallengeInstance
        """
        data = approve_passkeys_challenge_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.update_async(
            method="POST", uri=self._uri, data=data, headers=headers
        )

        return ApproveChallengeInstance(
            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.ApproveChallengeList>"
