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.api_response import ApiResponse
from twilio.base.instance_context import InstanceContext
from twilio.base.instance_resource import InstanceResource
from twilio.base.list_resource import ListResource
from twilio.base.version import Version


class NewChallengeInstance(InstanceResource):

    class CreatePasskeysChallengeRequest(object):
        """
        :ivar identity:
        :ivar factor_sid:
        """

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

            self.identity: Optional[str] = payload.get("identity")
            self.factor_sid: Optional[str] = payload.get("factor_sid")

        def to_dict(self):
            return {
                "identity": self.identity,
                "factor_sid": self.factor_sid,
            }

    """
    :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,
        }
        self._context: Optional[NewChallengeContext] = None

    @property
    def _proxy(self) -> "NewChallengeContext":
        """
        Generate an instance context for the instance, the context is capable of
        performing various actions. All instance actions are proxied to the context

        :returns: NewChallengeContext for this NewChallengeInstance
        """
        if self._context is None:
            self._context = NewChallengeContext(
                self._version,
                service_sid=self._solution["service_sid"],
            )
        return self._context

    def create(
        self, create_passkeys_challenge_request: CreatePasskeysChallengeRequest
    ) -> "NewChallengeInstance":
        """
        Create the NewChallengeInstance

        :param create_passkeys_challenge_request:

        :returns: The created NewChallengeInstance
        """
        return self._proxy.create(
            create_passkeys_challenge_request,
        )

    async def create_async(
        self, create_passkeys_challenge_request: CreatePasskeysChallengeRequest
    ) -> "NewChallengeInstance":
        """
        Asynchronous coroutine to create the NewChallengeInstance

        :param create_passkeys_challenge_request:

        :returns: The created NewChallengeInstance
        """
        return await self._proxy.create_async(
            create_passkeys_challenge_request,
        )

    def create_with_http_info(
        self, create_passkeys_challenge_request: CreatePasskeysChallengeRequest
    ) -> ApiResponse:
        """
        Create the NewChallengeInstance with HTTP info

        :param create_passkeys_challenge_request:

        :returns: ApiResponse with instance, status code, and headers
        """
        return self._proxy.create_with_http_info(
            create_passkeys_challenge_request,
        )

    async def create_with_http_info_async(
        self, create_passkeys_challenge_request: CreatePasskeysChallengeRequest
    ) -> ApiResponse:
        """
        Asynchronous coroutine to create the NewChallengeInstance with HTTP info

        :param create_passkeys_challenge_request:

        :returns: ApiResponse with instance, status code, and headers
        """
        return await self._proxy.create_with_http_info_async(
            create_passkeys_challenge_request,
        )

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


class NewChallengeContext(InstanceContext):

    class CreatePasskeysChallengeRequest(object):
        """
        :ivar identity:
        :ivar factor_sid:
        """

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

            self.identity: Optional[str] = payload.get("identity")
            self.factor_sid: Optional[str] = payload.get("factor_sid")

        def to_dict(self):
            return {
                "identity": self.identity,
                "factor_sid": self.factor_sid,
            }

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

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

    def _create(
        self, create_passkeys_challenge_request: CreatePasskeysChallengeRequest
    ) -> tuple:
        """
        Internal helper for create operation

        Returns:
            tuple: (payload, status_code, headers)
        """
        data = create_passkeys_challenge_request.to_dict()

        headers = values.of({})

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

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

        return self._version.create_with_response_info(
            method="POST", uri=self._uri, data=data, headers=headers
        )

    def create(
        self, create_passkeys_challenge_request: CreatePasskeysChallengeRequest
    ) -> NewChallengeInstance:
        """
        Create the NewChallengeInstance

        :param create_passkeys_challenge_request:

        :returns: The created NewChallengeInstance
        """
        payload, _, _ = self._create(
            create_passkeys_challenge_request=create_passkeys_challenge_request
        )
        return NewChallengeInstance(
            self._version, payload, service_sid=self._solution["service_sid"]
        )

    def create_with_http_info(
        self, create_passkeys_challenge_request: CreatePasskeysChallengeRequest
    ) -> ApiResponse:
        """
        Create the NewChallengeInstance and return response metadata

        :param create_passkeys_challenge_request:

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = self._create(
            create_passkeys_challenge_request=create_passkeys_challenge_request
        )
        instance = NewChallengeInstance(
            self._version, payload, service_sid=self._solution["service_sid"]
        )
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

    async def _create_async(
        self, create_passkeys_challenge_request: CreatePasskeysChallengeRequest
    ) -> tuple:
        """
        Internal async helper for create operation

        Returns:
            tuple: (payload, status_code, headers)
        """
        data = create_passkeys_challenge_request.to_dict()

        headers = values.of({})

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

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

        return await self._version.create_with_response_info_async(
            method="POST", uri=self._uri, data=data, headers=headers
        )

    async def create_async(
        self, create_passkeys_challenge_request: CreatePasskeysChallengeRequest
    ) -> NewChallengeInstance:
        """
        Asynchronous coroutine to create the NewChallengeInstance

        :param create_passkeys_challenge_request:

        :returns: The created NewChallengeInstance
        """
        payload, _, _ = await self._create_async(
            create_passkeys_challenge_request=create_passkeys_challenge_request
        )
        return NewChallengeInstance(
            self._version, payload, service_sid=self._solution["service_sid"]
        )

    async def create_with_http_info_async(
        self, create_passkeys_challenge_request: CreatePasskeysChallengeRequest
    ) -> ApiResponse:
        """
        Asynchronous coroutine to create the NewChallengeInstance and return response metadata

        :param create_passkeys_challenge_request:

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = await self._create_async(
            create_passkeys_challenge_request=create_passkeys_challenge_request
        )
        instance = NewChallengeInstance(
            self._version, payload, service_sid=self._solution["service_sid"]
        )
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

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


class NewChallengeList(ListResource):

    class CreatePasskeysChallengeRequest(object):
        """
        :ivar identity:
        :ivar factor_sid:
        """

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

            self.identity: Optional[str] = payload.get("identity")
            self.factor_sid: Optional[str] = payload.get("factor_sid")

        def to_dict(self):
            return {
                "identity": self.identity,
                "factor_sid": self.factor_sid,
            }

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

        :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,
        }

    def get(self) -> NewChallengeContext:
        """
        Constructs a NewChallengeContext

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

    def __call__(self) -> NewChallengeContext:
        """
        Constructs a NewChallengeContext

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

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

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