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

    Twilio - Flex
    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 typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator
from twilio.base import serialize, 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
from twilio.base.page import Page


class InsightsQuestionnairesInstance(InstanceResource):
    """
    :ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Flex Insights resource and owns this resource.
    :ivar questionnaire_sid: The sid of this questionnaire
    :ivar name: The name of this category.
    :ivar description: The description of this questionnaire
    :ivar active: The flag to enable or disable questionnaire
    :ivar questions: The list of questions with category for a questionnaire
    :ivar url:
    """

    def __init__(
        self,
        version: Version,
        payload: Dict[str, Any],
        questionnaire_sid: Optional[str] = None,
    ):
        super().__init__(version)

        self.account_sid: Optional[str] = payload.get("account_sid")
        self.questionnaire_sid: Optional[str] = payload.get("questionnaire_sid")
        self.name: Optional[str] = payload.get("name")
        self.description: Optional[str] = payload.get("description")
        self.active: Optional[bool] = payload.get("active")
        self.questions: Optional[List[Dict[str, object]]] = payload.get("questions")
        self.url: Optional[str] = payload.get("url")

        self._solution = {
            "questionnaire_sid": questionnaire_sid or self.questionnaire_sid,
        }
        self._context: Optional[InsightsQuestionnairesContext] = None

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

        :returns: InsightsQuestionnairesContext for this InsightsQuestionnairesInstance
        """
        if self._context is None:
            self._context = InsightsQuestionnairesContext(
                self._version,
                questionnaire_sid=self._solution["questionnaire_sid"],
            )
        return self._context

    def delete(self, authorization: Union[str, object] = values.unset) -> bool:
        """
        Deletes the InsightsQuestionnairesInstance

        :param authorization: The Authorization HTTP request header

        :returns: True if delete succeeds, False otherwise
        """
        return self._proxy.delete(
            authorization=authorization,
        )

    async def delete_async(
        self, authorization: Union[str, object] = values.unset
    ) -> bool:
        """
        Asynchronous coroutine that deletes the InsightsQuestionnairesInstance

        :param authorization: The Authorization HTTP request header

        :returns: True if delete succeeds, False otherwise
        """
        return await self._proxy.delete_async(
            authorization=authorization,
        )

    def delete_with_http_info(
        self, authorization: Union[str, object] = values.unset
    ) -> ApiResponse:
        """
        Deletes the InsightsQuestionnairesInstance with HTTP info

        :param authorization: The Authorization HTTP request header

        :returns: ApiResponse with success boolean, status code, and headers
        """
        return self._proxy.delete_with_http_info(
            authorization=authorization,
        )

    async def delete_with_http_info_async(
        self, authorization: Union[str, object] = values.unset
    ) -> ApiResponse:
        """
        Asynchronous coroutine that deletes the InsightsQuestionnairesInstance with HTTP info

        :param authorization: The Authorization HTTP request header

        :returns: ApiResponse with success boolean, status code, and headers
        """
        return await self._proxy.delete_with_http_info_async(
            authorization=authorization,
        )

    def fetch(
        self, authorization: Union[str, object] = values.unset
    ) -> "InsightsQuestionnairesInstance":
        """
        Fetch the InsightsQuestionnairesInstance

        :param authorization: The Authorization HTTP request header

        :returns: The fetched InsightsQuestionnairesInstance
        """
        return self._proxy.fetch(
            authorization=authorization,
        )

    async def fetch_async(
        self, authorization: Union[str, object] = values.unset
    ) -> "InsightsQuestionnairesInstance":
        """
        Asynchronous coroutine to fetch the InsightsQuestionnairesInstance

        :param authorization: The Authorization HTTP request header

        :returns: The fetched InsightsQuestionnairesInstance
        """
        return await self._proxy.fetch_async(
            authorization=authorization,
        )

    def fetch_with_http_info(
        self, authorization: Union[str, object] = values.unset
    ) -> ApiResponse:
        """
        Fetch the InsightsQuestionnairesInstance with HTTP info

        :param authorization: The Authorization HTTP request header

        :returns: ApiResponse with instance, status code, and headers
        """
        return self._proxy.fetch_with_http_info(
            authorization=authorization,
        )

    async def fetch_with_http_info_async(
        self, authorization: Union[str, object] = values.unset
    ) -> ApiResponse:
        """
        Asynchronous coroutine to fetch the InsightsQuestionnairesInstance with HTTP info

        :param authorization: The Authorization HTTP request header

        :returns: ApiResponse with instance, status code, and headers
        """
        return await self._proxy.fetch_with_http_info_async(
            authorization=authorization,
        )

    def update(
        self,
        active: bool,
        authorization: Union[str, object] = values.unset,
        name: Union[str, object] = values.unset,
        description: Union[str, object] = values.unset,
        question_sids: Union[List[str], object] = values.unset,
    ) -> "InsightsQuestionnairesInstance":
        """
        Update the InsightsQuestionnairesInstance

        :param active: The flag to enable or disable questionnaire
        :param authorization: The Authorization HTTP request header
        :param name: The name of this questionnaire
        :param description: The description of this questionnaire
        :param question_sids: The list of questions sids under a questionnaire

        :returns: The updated InsightsQuestionnairesInstance
        """
        return self._proxy.update(
            active=active,
            authorization=authorization,
            name=name,
            description=description,
            question_sids=question_sids,
        )

    async def update_async(
        self,
        active: bool,
        authorization: Union[str, object] = values.unset,
        name: Union[str, object] = values.unset,
        description: Union[str, object] = values.unset,
        question_sids: Union[List[str], object] = values.unset,
    ) -> "InsightsQuestionnairesInstance":
        """
        Asynchronous coroutine to update the InsightsQuestionnairesInstance

        :param active: The flag to enable or disable questionnaire
        :param authorization: The Authorization HTTP request header
        :param name: The name of this questionnaire
        :param description: The description of this questionnaire
        :param question_sids: The list of questions sids under a questionnaire

        :returns: The updated InsightsQuestionnairesInstance
        """
        return await self._proxy.update_async(
            active=active,
            authorization=authorization,
            name=name,
            description=description,
            question_sids=question_sids,
        )

    def update_with_http_info(
        self,
        active: bool,
        authorization: Union[str, object] = values.unset,
        name: Union[str, object] = values.unset,
        description: Union[str, object] = values.unset,
        question_sids: Union[List[str], object] = values.unset,
    ) -> ApiResponse:
        """
        Update the InsightsQuestionnairesInstance with HTTP info

        :param active: The flag to enable or disable questionnaire
        :param authorization: The Authorization HTTP request header
        :param name: The name of this questionnaire
        :param description: The description of this questionnaire
        :param question_sids: The list of questions sids under a questionnaire

        :returns: ApiResponse with instance, status code, and headers
        """
        return self._proxy.update_with_http_info(
            active=active,
            authorization=authorization,
            name=name,
            description=description,
            question_sids=question_sids,
        )

    async def update_with_http_info_async(
        self,
        active: bool,
        authorization: Union[str, object] = values.unset,
        name: Union[str, object] = values.unset,
        description: Union[str, object] = values.unset,
        question_sids: Union[List[str], object] = values.unset,
    ) -> ApiResponse:
        """
        Asynchronous coroutine to update the InsightsQuestionnairesInstance with HTTP info

        :param active: The flag to enable or disable questionnaire
        :param authorization: The Authorization HTTP request header
        :param name: The name of this questionnaire
        :param description: The description of this questionnaire
        :param question_sids: The list of questions sids under a questionnaire

        :returns: ApiResponse with instance, status code, and headers
        """
        return await self._proxy.update_with_http_info_async(
            active=active,
            authorization=authorization,
            name=name,
            description=description,
            question_sids=question_sids,
        )

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


class InsightsQuestionnairesContext(InstanceContext):

    def __init__(self, version: Version, questionnaire_sid: str):
        """
        Initialize the InsightsQuestionnairesContext

        :param version: Version that contains the resource
        :param questionnaire_sid: The SID of the questionnaire
        """
        super().__init__(version)

        # Path Solution
        self._solution = {
            "questionnaire_sid": questionnaire_sid,
        }
        self._uri = (
            "/Insights/QualityManagement/Questionnaires/{questionnaire_sid}".format(
                **self._solution
            )
        )

    def _delete(self, authorization: Union[str, object] = values.unset) -> tuple:
        """
        Internal helper for delete operation

        Returns:
            tuple: (success_boolean, status_code, headers)
        """
        headers = values.of(
            {
                "Authorization": authorization,
            }
        )

        headers = values.of({})

        return self._version.delete_with_response_info(
            method="DELETE", uri=self._uri, headers=headers
        )

    def delete(self, authorization: Union[str, object] = values.unset) -> bool:
        """
        Deletes the InsightsQuestionnairesInstance

        :param authorization: The Authorization HTTP request header

        :returns: True if delete succeeds, False otherwise
        """
        success, _, _ = self._delete(authorization=authorization)
        return success

    def delete_with_http_info(
        self, authorization: Union[str, object] = values.unset
    ) -> ApiResponse:
        """
        Deletes the InsightsQuestionnairesInstance and return response metadata

        :param authorization: The Authorization HTTP request header

        :returns: ApiResponse with success boolean, status code, and headers
        """
        success, status_code, headers = self._delete(authorization=authorization)
        return ApiResponse(data=success, status_code=status_code, headers=headers)

    async def _delete_async(
        self, authorization: Union[str, object] = values.unset
    ) -> tuple:
        """
        Internal async helper for delete operation

        Returns:
            tuple: (success_boolean, status_code, headers)
        """
        headers = values.of(
            {
                "Authorization": authorization,
            }
        )

        headers = values.of({})

        return await self._version.delete_with_response_info_async(
            method="DELETE", uri=self._uri, headers=headers
        )

    async def delete_async(
        self, authorization: Union[str, object] = values.unset
    ) -> bool:
        """
        Asynchronous coroutine that deletes the InsightsQuestionnairesInstance

        :param authorization: The Authorization HTTP request header

        :returns: True if delete succeeds, False otherwise
        """
        success, _, _ = await self._delete_async(authorization=authorization)
        return success

    async def delete_with_http_info_async(
        self, authorization: Union[str, object] = values.unset
    ) -> ApiResponse:
        """
        Asynchronous coroutine that deletes the InsightsQuestionnairesInstance and return response metadata

        :param authorization: The Authorization HTTP request header

        :returns: ApiResponse with success boolean, status code, and headers
        """
        success, status_code, headers = await self._delete_async(
            authorization=authorization
        )
        return ApiResponse(data=success, status_code=status_code, headers=headers)

    def _fetch(self, authorization: Union[str, object] = values.unset) -> tuple:
        """
        Internal helper for fetch operation

        Returns:
            tuple: (payload, status_code, headers)
        """

        headers = values.of({})

        if not (
            authorization is values.unset
            or (isinstance(authorization, str) and not authorization)
        ):
            headers["Authorization"] = authorization

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

        return self._version.fetch_with_response_info(
            method="GET", uri=self._uri, headers=headers
        )

    def fetch(
        self, authorization: Union[str, object] = values.unset
    ) -> InsightsQuestionnairesInstance:
        """
        Fetch the InsightsQuestionnairesInstance

        :param authorization: The Authorization HTTP request header

        :returns: The fetched InsightsQuestionnairesInstance
        """
        payload, _, _ = self._fetch(authorization=authorization)
        return InsightsQuestionnairesInstance(
            self._version,
            payload,
            questionnaire_sid=self._solution["questionnaire_sid"],
        )

    def fetch_with_http_info(
        self, authorization: Union[str, object] = values.unset
    ) -> ApiResponse:
        """
        Fetch the InsightsQuestionnairesInstance and return response metadata

        :param authorization: The Authorization HTTP request header

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = self._fetch(authorization=authorization)
        instance = InsightsQuestionnairesInstance(
            self._version,
            payload,
            questionnaire_sid=self._solution["questionnaire_sid"],
        )
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

    async def _fetch_async(
        self, authorization: Union[str, object] = values.unset
    ) -> tuple:
        """
        Internal async helper for fetch operation

        Returns:
            tuple: (payload, status_code, headers)
        """

        headers = values.of({})

        if not (
            authorization is values.unset
            or (isinstance(authorization, str) and not authorization)
        ):
            headers["Authorization"] = authorization

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

        return await self._version.fetch_with_response_info_async(
            method="GET", uri=self._uri, headers=headers
        )

    async def fetch_async(
        self, authorization: Union[str, object] = values.unset
    ) -> InsightsQuestionnairesInstance:
        """
        Asynchronous coroutine to fetch the InsightsQuestionnairesInstance

        :param authorization: The Authorization HTTP request header

        :returns: The fetched InsightsQuestionnairesInstance
        """
        payload, _, _ = await self._fetch_async(authorization=authorization)
        return InsightsQuestionnairesInstance(
            self._version,
            payload,
            questionnaire_sid=self._solution["questionnaire_sid"],
        )

    async def fetch_with_http_info_async(
        self, authorization: Union[str, object] = values.unset
    ) -> ApiResponse:
        """
        Asynchronous coroutine to fetch the InsightsQuestionnairesInstance and return response metadata

        :param authorization: The Authorization HTTP request header

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = await self._fetch_async(
            authorization=authorization
        )
        instance = InsightsQuestionnairesInstance(
            self._version,
            payload,
            questionnaire_sid=self._solution["questionnaire_sid"],
        )
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

    def _update(
        self,
        active: bool,
        authorization: Union[str, object] = values.unset,
        name: Union[str, object] = values.unset,
        description: Union[str, object] = values.unset,
        question_sids: Union[List[str], object] = values.unset,
    ) -> tuple:
        """
        Internal helper for update operation

        Returns:
            tuple: (payload, status_code, headers)
        """

        data = values.of(
            {
                "Active": serialize.boolean_to_string(active),
                "Name": name,
                "Description": description,
                "QuestionSids": serialize.map(question_sids, lambda e: e),
            }
        )
        headers = values.of({})

        if not (
            authorization is values.unset
            or (isinstance(authorization, str) and not authorization)
        ):
            headers["Authorization"] = authorization

        headers["Content-Type"] = "application/x-www-form-urlencoded"

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

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

    def update(
        self,
        active: bool,
        authorization: Union[str, object] = values.unset,
        name: Union[str, object] = values.unset,
        description: Union[str, object] = values.unset,
        question_sids: Union[List[str], object] = values.unset,
    ) -> InsightsQuestionnairesInstance:
        """
        Update the InsightsQuestionnairesInstance

        :param active: The flag to enable or disable questionnaire
        :param authorization: The Authorization HTTP request header
        :param name: The name of this questionnaire
        :param description: The description of this questionnaire
        :param question_sids: The list of questions sids under a questionnaire

        :returns: The updated InsightsQuestionnairesInstance
        """
        payload, _, _ = self._update(
            active=active,
            authorization=authorization,
            name=name,
            description=description,
            question_sids=question_sids,
        )
        return InsightsQuestionnairesInstance(
            self._version,
            payload,
            questionnaire_sid=self._solution["questionnaire_sid"],
        )

    def update_with_http_info(
        self,
        active: bool,
        authorization: Union[str, object] = values.unset,
        name: Union[str, object] = values.unset,
        description: Union[str, object] = values.unset,
        question_sids: Union[List[str], object] = values.unset,
    ) -> ApiResponse:
        """
        Update the InsightsQuestionnairesInstance and return response metadata

        :param active: The flag to enable or disable questionnaire
        :param authorization: The Authorization HTTP request header
        :param name: The name of this questionnaire
        :param description: The description of this questionnaire
        :param question_sids: The list of questions sids under a questionnaire

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = self._update(
            active=active,
            authorization=authorization,
            name=name,
            description=description,
            question_sids=question_sids,
        )
        instance = InsightsQuestionnairesInstance(
            self._version,
            payload,
            questionnaire_sid=self._solution["questionnaire_sid"],
        )
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

    async def _update_async(
        self,
        active: bool,
        authorization: Union[str, object] = values.unset,
        name: Union[str, object] = values.unset,
        description: Union[str, object] = values.unset,
        question_sids: Union[List[str], object] = values.unset,
    ) -> tuple:
        """
        Internal async helper for update operation

        Returns:
            tuple: (payload, status_code, headers)
        """

        data = values.of(
            {
                "Active": serialize.boolean_to_string(active),
                "Name": name,
                "Description": description,
                "QuestionSids": serialize.map(question_sids, lambda e: e),
            }
        )
        headers = values.of({})

        if not (
            authorization is values.unset
            or (isinstance(authorization, str) and not authorization)
        ):
            headers["Authorization"] = authorization

        headers["Content-Type"] = "application/x-www-form-urlencoded"

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

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

    async def update_async(
        self,
        active: bool,
        authorization: Union[str, object] = values.unset,
        name: Union[str, object] = values.unset,
        description: Union[str, object] = values.unset,
        question_sids: Union[List[str], object] = values.unset,
    ) -> InsightsQuestionnairesInstance:
        """
        Asynchronous coroutine to update the InsightsQuestionnairesInstance

        :param active: The flag to enable or disable questionnaire
        :param authorization: The Authorization HTTP request header
        :param name: The name of this questionnaire
        :param description: The description of this questionnaire
        :param question_sids: The list of questions sids under a questionnaire

        :returns: The updated InsightsQuestionnairesInstance
        """
        payload, _, _ = await self._update_async(
            active=active,
            authorization=authorization,
            name=name,
            description=description,
            question_sids=question_sids,
        )
        return InsightsQuestionnairesInstance(
            self._version,
            payload,
            questionnaire_sid=self._solution["questionnaire_sid"],
        )

    async def update_with_http_info_async(
        self,
        active: bool,
        authorization: Union[str, object] = values.unset,
        name: Union[str, object] = values.unset,
        description: Union[str, object] = values.unset,
        question_sids: Union[List[str], object] = values.unset,
    ) -> ApiResponse:
        """
        Asynchronous coroutine to update the InsightsQuestionnairesInstance and return response metadata

        :param active: The flag to enable or disable questionnaire
        :param authorization: The Authorization HTTP request header
        :param name: The name of this questionnaire
        :param description: The description of this questionnaire
        :param question_sids: The list of questions sids under a questionnaire

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = await self._update_async(
            active=active,
            authorization=authorization,
            name=name,
            description=description,
            question_sids=question_sids,
        )
        instance = InsightsQuestionnairesInstance(
            self._version,
            payload,
            questionnaire_sid=self._solution["questionnaire_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.FlexApi.V1.InsightsQuestionnairesContext {}>".format(context)


class InsightsQuestionnairesPage(Page):

    def get_instance(self, payload: Dict[str, Any]) -> InsightsQuestionnairesInstance:
        """
        Build an instance of InsightsQuestionnairesInstance

        :param payload: Payload response from the API
        """
        return InsightsQuestionnairesInstance(self._version, payload)

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

        :returns: Machine friendly representation
        """
        return "<Twilio.FlexApi.V1.InsightsQuestionnairesPage>"


class InsightsQuestionnairesList(ListResource):

    def __init__(self, version: Version):
        """
        Initialize the InsightsQuestionnairesList

        :param version: Version that contains the resource

        """
        super().__init__(version)

        self._uri = "/Insights/QualityManagement/Questionnaires"

    def _create(
        self,
        name: str,
        authorization: Union[str, object] = values.unset,
        description: Union[str, object] = values.unset,
        active: Union[bool, object] = values.unset,
        question_sids: Union[List[str], object] = values.unset,
    ) -> tuple:
        """
        Internal helper for create operation

        Returns:
            tuple: (payload, status_code, headers)
        """

        data = values.of(
            {
                "Name": name,
                "Description": description,
                "Active": serialize.boolean_to_string(active),
                "QuestionSids": serialize.map(question_sids, lambda e: e),
            }
        )
        headers = values.of(
            {
                "Authorization": authorization,
                "Content-Type": "application/x-www-form-urlencoded",
            }
        )

        headers["Content-Type"] = "application/x-www-form-urlencoded"

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

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

    def create(
        self,
        name: str,
        authorization: Union[str, object] = values.unset,
        description: Union[str, object] = values.unset,
        active: Union[bool, object] = values.unset,
        question_sids: Union[List[str], object] = values.unset,
    ) -> InsightsQuestionnairesInstance:
        """
        Create the InsightsQuestionnairesInstance

        :param name: The name of this questionnaire
        :param authorization: The Authorization HTTP request header
        :param description: The description of this questionnaire
        :param active: The flag to enable or disable questionnaire
        :param question_sids: The list of questions sids under a questionnaire

        :returns: The created InsightsQuestionnairesInstance
        """
        payload, _, _ = self._create(
            name=name,
            authorization=authorization,
            description=description,
            active=active,
            question_sids=question_sids,
        )
        return InsightsQuestionnairesInstance(self._version, payload)

    def create_with_http_info(
        self,
        name: str,
        authorization: Union[str, object] = values.unset,
        description: Union[str, object] = values.unset,
        active: Union[bool, object] = values.unset,
        question_sids: Union[List[str], object] = values.unset,
    ) -> ApiResponse:
        """
        Create the InsightsQuestionnairesInstance and return response metadata

        :param name: The name of this questionnaire
        :param authorization: The Authorization HTTP request header
        :param description: The description of this questionnaire
        :param active: The flag to enable or disable questionnaire
        :param question_sids: The list of questions sids under a questionnaire

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = self._create(
            name=name,
            authorization=authorization,
            description=description,
            active=active,
            question_sids=question_sids,
        )
        instance = InsightsQuestionnairesInstance(self._version, payload)
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

    async def _create_async(
        self,
        name: str,
        authorization: Union[str, object] = values.unset,
        description: Union[str, object] = values.unset,
        active: Union[bool, object] = values.unset,
        question_sids: Union[List[str], object] = values.unset,
    ) -> tuple:
        """
        Internal async helper for create operation

        Returns:
            tuple: (payload, status_code, headers)
        """

        data = values.of(
            {
                "Name": name,
                "Description": description,
                "Active": serialize.boolean_to_string(active),
                "QuestionSids": serialize.map(question_sids, lambda e: e),
            }
        )
        headers = values.of(
            {
                "Authorization": authorization,
                "Content-Type": "application/x-www-form-urlencoded",
            }
        )

        headers["Content-Type"] = "application/x-www-form-urlencoded"

        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,
        name: str,
        authorization: Union[str, object] = values.unset,
        description: Union[str, object] = values.unset,
        active: Union[bool, object] = values.unset,
        question_sids: Union[List[str], object] = values.unset,
    ) -> InsightsQuestionnairesInstance:
        """
        Asynchronously create the InsightsQuestionnairesInstance

        :param name: The name of this questionnaire
        :param authorization: The Authorization HTTP request header
        :param description: The description of this questionnaire
        :param active: The flag to enable or disable questionnaire
        :param question_sids: The list of questions sids under a questionnaire

        :returns: The created InsightsQuestionnairesInstance
        """
        payload, _, _ = await self._create_async(
            name=name,
            authorization=authorization,
            description=description,
            active=active,
            question_sids=question_sids,
        )
        return InsightsQuestionnairesInstance(self._version, payload)

    async def create_with_http_info_async(
        self,
        name: str,
        authorization: Union[str, object] = values.unset,
        description: Union[str, object] = values.unset,
        active: Union[bool, object] = values.unset,
        question_sids: Union[List[str], object] = values.unset,
    ) -> ApiResponse:
        """
        Asynchronously create the InsightsQuestionnairesInstance and return response metadata

        :param name: The name of this questionnaire
        :param authorization: The Authorization HTTP request header
        :param description: The description of this questionnaire
        :param active: The flag to enable or disable questionnaire
        :param question_sids: The list of questions sids under a questionnaire

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = await self._create_async(
            name=name,
            authorization=authorization,
            description=description,
            active=active,
            question_sids=question_sids,
        )
        instance = InsightsQuestionnairesInstance(self._version, payload)
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

    def stream(
        self,
        authorization: Union[str, object] = values.unset,
        include_inactive: Union[bool, object] = values.unset,
        limit: Optional[int] = None,
        page_size: Optional[int] = None,
    ) -> Iterator[InsightsQuestionnairesInstance]:
        """
        Streams InsightsQuestionnairesInstance records from the API as a generator stream.
        This operation lazily loads records as efficiently as possible until the limit
        is reached.
        The results are returned as a generator, so this operation is memory efficient.

        :param str authorization: The Authorization HTTP request header
        :param bool include_inactive: Flag indicating whether to include inactive questionnaires or not
        :param limit: Upper limit for the number of records to return. stream()
                      guarantees to never return more than limit.  Default is no limit
        :param page_size: Number of records to fetch per request, when not set will use
                          the default value of 50 records.  If no page_size is defined
                          but a limit is defined, stream() will attempt to read the
                          limit with the most efficient page size, i.e. min(limit, 1000)

        :returns: Generator that will yield up to limit results
        """
        limits = self._version.read_limits(limit, page_size)
        page = self.page(
            authorization=authorization,
            include_inactive=include_inactive,
            page_size=limits["page_size"],
        )

        return self._version.stream(page, limits["limit"])

    async def stream_async(
        self,
        authorization: Union[str, object] = values.unset,
        include_inactive: Union[bool, object] = values.unset,
        limit: Optional[int] = None,
        page_size: Optional[int] = None,
    ) -> AsyncIterator[InsightsQuestionnairesInstance]:
        """
        Asynchronously streams InsightsQuestionnairesInstance records from the API as a generator stream.
        This operation lazily loads records as efficiently as possible until the limit
        is reached.
        The results are returned as a generator, so this operation is memory efficient.

        :param str authorization: The Authorization HTTP request header
        :param bool include_inactive: Flag indicating whether to include inactive questionnaires or not
        :param limit: Upper limit for the number of records to return. stream()
                      guarantees to never return more than limit.  Default is no limit
        :param page_size: Number of records to fetch per request, when not set will use
                          the default value of 50 records.  If no page_size is defined
                          but a limit is defined, stream() will attempt to read the
                          limit with the most efficient page size, i.e. min(limit, 1000)

        :returns: Generator that will yield up to limit results
        """
        limits = self._version.read_limits(limit, page_size)
        page = await self.page_async(
            authorization=authorization,
            include_inactive=include_inactive,
            page_size=limits["page_size"],
        )

        return self._version.stream_async(page, limits["limit"])

    def stream_with_http_info(
        self,
        authorization: Union[str, object] = values.unset,
        include_inactive: Union[bool, object] = values.unset,
        limit: Optional[int] = None,
        page_size: Optional[int] = None,
    ) -> tuple:
        """
        Streams InsightsQuestionnairesInstance and returns headers from first page


        :param str authorization: The Authorization HTTP request header
        :param bool include_inactive: Flag indicating whether to include inactive questionnaires or not
        :param limit: Upper limit for the number of records to return. stream()
                      guarantees to never return more than limit.  Default is no limit
        :param page_size: Number of records to fetch per request, when not set will use
                          the default value of 50 records.  If no page_size is defined
                          but a limit is defined, stream() will attempt to read the
                          limit with the most efficient page size, i.e. min(limit, 1000)

        :returns: tuple of (generator, status_code, headers) where generator yields instances
        """
        limits = self._version.read_limits(limit, page_size)
        page_response = self.page_with_http_info(
            authorization=authorization,
            include_inactive=include_inactive,
            page_size=limits["page_size"],
        )

        generator = self._version.stream(page_response.data, limits["limit"])
        return (generator, page_response.status_code, page_response.headers)

    async def stream_with_http_info_async(
        self,
        authorization: Union[str, object] = values.unset,
        include_inactive: Union[bool, object] = values.unset,
        limit: Optional[int] = None,
        page_size: Optional[int] = None,
    ) -> tuple:
        """
        Asynchronously streams InsightsQuestionnairesInstance and returns headers from first page


        :param str authorization: The Authorization HTTP request header
        :param bool include_inactive: Flag indicating whether to include inactive questionnaires or not
        :param limit: Upper limit for the number of records to return. stream()
                      guarantees to never return more than limit.  Default is no limit
        :param page_size: Number of records to fetch per request, when not set will use
                          the default value of 50 records.  If no page_size is defined
                          but a limit is defined, stream() will attempt to read the
                          limit with the most efficient page size, i.e. min(limit, 1000)

        :returns: tuple of (generator, status_code, headers) where generator yields instances
        """
        limits = self._version.read_limits(limit, page_size)
        page_response = await self.page_with_http_info_async(
            authorization=authorization,
            include_inactive=include_inactive,
            page_size=limits["page_size"],
        )

        generator = self._version.stream_async(page_response.data, limits["limit"])
        return (generator, page_response.status_code, page_response.headers)

    def list(
        self,
        authorization: Union[str, object] = values.unset,
        include_inactive: Union[bool, object] = values.unset,
        limit: Optional[int] = None,
        page_size: Optional[int] = None,
    ) -> List[InsightsQuestionnairesInstance]:
        """
        Lists InsightsQuestionnairesInstance records from the API as a list.
        Unlike stream(), this operation is eager and will load `limit` records into
        memory before returning.

        :param str authorization: The Authorization HTTP request header
        :param bool include_inactive: Flag indicating whether to include inactive questionnaires or not
        :param limit: Upper limit for the number of records to return. list() guarantees
                      never to return more than limit.  Default is no limit
        :param page_size: Number of records to fetch per request, when not set will use
                          the default value of 50 records.  If no page_size is defined
                          but a limit is defined, list() will attempt to read the limit
                          with the most efficient page size, i.e. min(limit, 1000)

        :returns: list that will contain up to limit results
        """
        return list(
            self.stream(
                authorization=authorization,
                include_inactive=include_inactive,
                limit=limit,
                page_size=page_size,
            )
        )

    async def list_async(
        self,
        authorization: Union[str, object] = values.unset,
        include_inactive: Union[bool, object] = values.unset,
        limit: Optional[int] = None,
        page_size: Optional[int] = None,
    ) -> List[InsightsQuestionnairesInstance]:
        """
        Asynchronously lists InsightsQuestionnairesInstance records from the API as a list.
        Unlike stream(), this operation is eager and will load `limit` records into
        memory before returning.

        :param str authorization: The Authorization HTTP request header
        :param bool include_inactive: Flag indicating whether to include inactive questionnaires or not
        :param limit: Upper limit for the number of records to return. list() guarantees
                      never to return more than limit.  Default is no limit
        :param page_size: Number of records to fetch per request, when not set will use
                          the default value of 50 records.  If no page_size is defined
                          but a limit is defined, list() will attempt to read the limit
                          with the most efficient page size, i.e. min(limit, 1000)

        :returns: list that will contain up to limit results
        """
        return [
            record
            async for record in await self.stream_async(
                authorization=authorization,
                include_inactive=include_inactive,
                limit=limit,
                page_size=page_size,
            )
        ]

    def list_with_http_info(
        self,
        authorization: Union[str, object] = values.unset,
        include_inactive: Union[bool, object] = values.unset,
        limit: Optional[int] = None,
        page_size: Optional[int] = None,
    ) -> ApiResponse:
        """
        Lists InsightsQuestionnairesInstance and returns headers from first page


        :param str authorization: The Authorization HTTP request header
        :param bool include_inactive: Flag indicating whether to include inactive questionnaires or not
        :param limit: Upper limit for the number of records to return. list() guarantees
                      never to return more than limit.  Default is no limit
        :param page_size: Number of records to fetch per request, when not set will use
                          the default value of 50 records.  If no page_size is defined
                          but a limit is defined, list() will attempt to read the limit
                          with the most efficient page size, i.e. min(limit, 1000)

        :returns: ApiResponse with list of instances, status code, and headers
        """
        generator, status_code, headers = self.stream_with_http_info(
            authorization=authorization,
            include_inactive=include_inactive,
            limit=limit,
            page_size=page_size,
        )
        items = list(generator)
        return ApiResponse(data=items, status_code=status_code, headers=headers)

    async def list_with_http_info_async(
        self,
        authorization: Union[str, object] = values.unset,
        include_inactive: Union[bool, object] = values.unset,
        limit: Optional[int] = None,
        page_size: Optional[int] = None,
    ) -> ApiResponse:
        """
        Asynchronously lists InsightsQuestionnairesInstance and returns headers from first page


        :param str authorization: The Authorization HTTP request header
        :param bool include_inactive: Flag indicating whether to include inactive questionnaires or not
        :param limit: Upper limit for the number of records to return. list() guarantees
                      never to return more than limit.  Default is no limit
        :param page_size: Number of records to fetch per request, when not set will use
                          the default value of 50 records.  If no page_size is defined
                          but a limit is defined, list() will attempt to read the limit
                          with the most efficient page size, i.e. min(limit, 1000)

        :returns: ApiResponse with list of instances, status code, and headers
        """
        generator, status_code, headers = await self.stream_with_http_info_async(
            authorization=authorization,
            include_inactive=include_inactive,
            limit=limit,
            page_size=page_size,
        )
        items = [record async for record in generator]
        return ApiResponse(data=items, status_code=status_code, headers=headers)

    def page(
        self,
        authorization: Union[str, object] = values.unset,
        include_inactive: Union[bool, object] = values.unset,
        page_token: Union[str, object] = values.unset,
        page_number: Union[int, object] = values.unset,
        page_size: Union[int, object] = values.unset,
    ) -> InsightsQuestionnairesPage:
        """
        Retrieve a single page of InsightsQuestionnairesInstance records from the API.
        Request is executed immediately

        :param authorization: The Authorization HTTP request header
        :param include_inactive: Flag indicating whether to include inactive questionnaires or not
        :param page_token: PageToken provided by the API
        :param page_number: Page Number, this value is simply for client state
        :param page_size: Number of records to return, defaults to 50

        :returns: Page of InsightsQuestionnairesInstance
        """
        data = values.of(
            {
                "Authorization": authorization,
                "IncludeInactive": serialize.boolean_to_string(include_inactive),
                "PageToken": page_token,
                "Page": page_number,
                "PageSize": page_size,
            }
        )

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

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

        response = self._version.page(
            method="GET", uri=self._uri, params=data, headers=headers
        )
        return InsightsQuestionnairesPage(self._version, response)

    async def page_async(
        self,
        authorization: Union[str, object] = values.unset,
        include_inactive: Union[bool, object] = values.unset,
        page_token: Union[str, object] = values.unset,
        page_number: Union[int, object] = values.unset,
        page_size: Union[int, object] = values.unset,
    ) -> InsightsQuestionnairesPage:
        """
        Asynchronously retrieve a single page of InsightsQuestionnairesInstance records from the API.
        Request is executed immediately

        :param authorization: The Authorization HTTP request header
        :param include_inactive: Flag indicating whether to include inactive questionnaires or not
        :param page_token: PageToken provided by the API
        :param page_number: Page Number, this value is simply for client state
        :param page_size: Number of records to return, defaults to 50

        :returns: Page of InsightsQuestionnairesInstance
        """
        data = values.of(
            {
                "Authorization": authorization,
                "IncludeInactive": serialize.boolean_to_string(include_inactive),
                "PageToken": page_token,
                "Page": page_number,
                "PageSize": page_size,
            }
        )

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

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

        response = await self._version.page_async(
            method="GET", uri=self._uri, params=data, headers=headers
        )
        return InsightsQuestionnairesPage(self._version, response)

    def page_with_http_info(
        self,
        authorization: Union[str, object] = values.unset,
        include_inactive: Union[bool, object] = values.unset,
        page_token: Union[str, object] = values.unset,
        page_number: Union[int, object] = values.unset,
        page_size: Union[int, object] = values.unset,
    ) -> ApiResponse:
        """
        Retrieve a single page with response metadata


        :param authorization: The Authorization HTTP request header
        :param include_inactive: Flag indicating whether to include inactive questionnaires or not
        :param page_token: PageToken provided by the API
        :param page_number: Page Number, this value is simply for client state
        :param page_size: Number of records to return, defaults to 50

        :returns: ApiResponse with InsightsQuestionnairesPage, status code, and headers
        """
        data = values.of(
            {
                "Authorization": authorization,
                "IncludeInactive": serialize.boolean_to_string(include_inactive),
                "PageToken": page_token,
                "Page": page_number,
                "PageSize": page_size,
            }
        )

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

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

        response, status_code, response_headers = self._version.page_with_response_info(
            method="GET", uri=self._uri, params=data, headers=headers
        )
        page = InsightsQuestionnairesPage(self._version, response)
        return ApiResponse(data=page, status_code=status_code, headers=response_headers)

    async def page_with_http_info_async(
        self,
        authorization: Union[str, object] = values.unset,
        include_inactive: Union[bool, object] = values.unset,
        page_token: Union[str, object] = values.unset,
        page_number: Union[int, object] = values.unset,
        page_size: Union[int, object] = values.unset,
    ) -> ApiResponse:
        """
        Asynchronously retrieve a single page with response metadata


        :param authorization: The Authorization HTTP request header
        :param include_inactive: Flag indicating whether to include inactive questionnaires or not
        :param page_token: PageToken provided by the API
        :param page_number: Page Number, this value is simply for client state
        :param page_size: Number of records to return, defaults to 50

        :returns: ApiResponse with InsightsQuestionnairesPage, status code, and headers
        """
        data = values.of(
            {
                "Authorization": authorization,
                "IncludeInactive": serialize.boolean_to_string(include_inactive),
                "PageToken": page_token,
                "Page": page_number,
                "PageSize": page_size,
            }
        )

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

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

        response, status_code, response_headers = (
            await self._version.page_with_response_info_async(
                method="GET", uri=self._uri, params=data, headers=headers
            )
        )
        page = InsightsQuestionnairesPage(self._version, response)
        return ApiResponse(data=page, status_code=status_code, headers=response_headers)

    def get_page(self, target_url: str) -> InsightsQuestionnairesPage:
        """
        Retrieve a specific page of InsightsQuestionnairesInstance records from the API.
        Request is executed immediately

        :param target_url: API-generated URL for the requested results page

        :returns: Page of InsightsQuestionnairesInstance
        """
        response = self._version.domain.twilio.request("GET", target_url)
        return InsightsQuestionnairesPage(self._version, response)

    async def get_page_async(self, target_url: str) -> InsightsQuestionnairesPage:
        """
        Asynchronously retrieve a specific page of InsightsQuestionnairesInstance records from the API.
        Request is executed immediately

        :param target_url: API-generated URL for the requested results page

        :returns: Page of InsightsQuestionnairesInstance
        """
        response = await self._version.domain.twilio.request_async("GET", target_url)
        return InsightsQuestionnairesPage(self._version, response)

    def get(self, questionnaire_sid: str) -> InsightsQuestionnairesContext:
        """
        Constructs a InsightsQuestionnairesContext

        :param questionnaire_sid: The SID of the questionnaire
        """
        return InsightsQuestionnairesContext(
            self._version, questionnaire_sid=questionnaire_sid
        )

    def __call__(self, questionnaire_sid: str) -> InsightsQuestionnairesContext:
        """
        Constructs a InsightsQuestionnairesContext

        :param questionnaire_sid: The SID of the questionnaire
        """
        return InsightsQuestionnairesContext(
            self._version, questionnaire_sid=questionnaire_sid
        )

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

        :returns: Machine friendly representation
        """
        return "<Twilio.FlexApi.V1.InsightsQuestionnairesList>"
