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 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
from twilio.base.page import Page


class InsightsConversationsInstance(InstanceResource):
    def __init__(self, version, payload):
        """
        Initialize the InsightsConversationsInstance

        :returns: twilio.rest.flex_api.v1.insights_conversations.InsightsConversationsInstance
        :rtype: twilio.rest.flex_api.v1.insights_conversations.InsightsConversationsInstance
        """
        super().__init__(version)

        self._properties = {
            "account_id": payload.get("account_id"),
            "conversation_id": payload.get("conversation_id"),
            "segment_count": deserialize.integer(payload.get("segment_count")),
            "segments": payload.get("segments"),
        }

        self._solution = {}

    @property
    def account_id(self):
        """
        :returns: The id of the account.
        :rtype: str
        """
        return self._properties["account_id"]

    @property
    def conversation_id(self):
        """
        :returns: The unique id of the conversation
        :rtype: str
        """
        return self._properties["conversation_id"]

    @property
    def segment_count(self):
        """
        :returns: The count of segments for a conversation
        :rtype: int
        """
        return self._properties["segment_count"]

    @property
    def segments(self):
        """
        :returns: The Segments of a conversation
        :rtype: list[object]
        """
        return self._properties["segments"]

    def __repr__(self):
        """
        Provide a friendly representation

        :returns: Machine friendly representation
        :rtype: str
        """
        context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
        return "<Twilio.FlexApi.V1.InsightsConversationsInstance {}>".format(context)


class InsightsConversationsPage(Page):
    def get_instance(self, payload):
        """
        Build an instance of InsightsConversationsInstance

        :param dict payload: Payload response from the API

        :returns: twilio.rest.flex_api.v1.insights_conversations.InsightsConversationsInstance
        :rtype: twilio.rest.flex_api.v1.insights_conversations.InsightsConversationsInstance
        """
        return InsightsConversationsInstance(self._version, payload)

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

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


class InsightsConversationsList(ListResource):
    def __init__(self, version: Version):
        """
        Initialize the InsightsConversationsList

        :param Version version: Version that contains the resource

        :returns: twilio.rest.flex_api.v1.insights_conversations.InsightsConversationsList
        :rtype: twilio.rest.flex_api.v1.insights_conversations.InsightsConversationsList
        """
        super().__init__(version)

        self._uri = "/Insights/Conversations"

    def stream(
        self, token=values.unset, segment_id=values.unset, limit=None, page_size=None
    ):
        """
        Streams InsightsConversationsInstance 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 token: The Token HTTP request header
        :param str segment_id: Unique Id of the segment for which conversation details needs to be fetched
        :param int limit: Upper limit for the number of records to return. stream()
                          guarantees to never return more than limit.  Default is no limit
        :param int 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
        :rtype: list[twilio.rest.flex_api.v1.insights_conversations.InsightsConversationsInstance]
        """
        limits = self._version.read_limits(limit, page_size)
        page = self.page(
            token=token, segment_id=segment_id, page_size=limits["page_size"]
        )

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

    async def stream_async(
        self, token=values.unset, segment_id=values.unset, limit=None, page_size=None
    ):
        """
        Asynchronously streams InsightsConversationsInstance 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 token: The Token HTTP request header
        :param str segment_id: Unique Id of the segment for which conversation details needs to be fetched
        :param int limit: Upper limit for the number of records to return. stream()
                          guarantees to never return more than limit.  Default is no limit
        :param int 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
        :rtype: list[twilio.rest.flex_api.v1.insights_conversations.InsightsConversationsInstance]
        """
        limits = self._version.read_limits(limit, page_size)
        page = await self.page_async(
            token=token, segment_id=segment_id, page_size=limits["page_size"]
        )

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

    def list(
        self, token=values.unset, segment_id=values.unset, limit=None, page_size=None
    ):
        """
        Lists InsightsConversationsInstance records from the API as a list.
        Unlike stream(), this operation is eager and will load `limit` records into
        memory before returning.

        :param str token: The Token HTTP request header
        :param str segment_id: Unique Id of the segment for which conversation details needs to be fetched
        :param int limit: Upper limit for the number of records to return. list() guarantees
                          never to return more than limit.  Default is no limit
        :param int 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: Generator that will yield up to limit results
        :rtype: list[twilio.rest.flex_api.v1.insights_conversations.InsightsConversationsInstance]
        """
        return list(
            self.stream(
                token=token,
                segment_id=segment_id,
                limit=limit,
                page_size=page_size,
            )
        )

    async def list_async(
        self, token=values.unset, segment_id=values.unset, limit=None, page_size=None
    ):
        """
        Asynchronously lists InsightsConversationsInstance records from the API as a list.
        Unlike stream(), this operation is eager and will load `limit` records into
        memory before returning.

        :param str token: The Token HTTP request header
        :param str segment_id: Unique Id of the segment for which conversation details needs to be fetched
        :param int limit: Upper limit for the number of records to return. list() guarantees
                          never to return more than limit.  Default is no limit
        :param int 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: Generator that will yield up to limit results
        :rtype: list[twilio.rest.flex_api.v1.insights_conversations.InsightsConversationsInstance]
        """
        return list(
            await self.stream_async(
                token=token,
                segment_id=segment_id,
                limit=limit,
                page_size=page_size,
            )
        )

    def page(
        self,
        token=values.unset,
        segment_id=values.unset,
        page_token=values.unset,
        page_number=values.unset,
        page_size=values.unset,
    ):
        """
        Retrieve a single page of InsightsConversationsInstance records from the API.
        Request is executed immediately

        :param str token: The Token HTTP request header
        :param str segment_id: Unique Id of the segment for which conversation details needs to be fetched
        :param str page_token: PageToken provided by the API
        :param int page_number: Page Number, this value is simply for client state
        :param int page_size: Number of records to return, defaults to 50

        :returns: Page of InsightsConversationsInstance
        :rtype: twilio.rest.flex_api.v1.insights_conversations.InsightsConversationsPage
        """
        data = values.of(
            {
                "Token": token,
                "SegmentId": segment_id,
                "PageToken": page_token,
                "Page": page_number,
                "PageSize": page_size,
            }
        )

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

    async def page_async(
        self,
        token=values.unset,
        segment_id=values.unset,
        page_token=values.unset,
        page_number=values.unset,
        page_size=values.unset,
    ):
        """
        Asynchronously retrieve a single page of InsightsConversationsInstance records from the API.
        Request is executed immediately

        :param str token: The Token HTTP request header
        :param str segment_id: Unique Id of the segment for which conversation details needs to be fetched
        :param str page_token: PageToken provided by the API
        :param int page_number: Page Number, this value is simply for client state
        :param int page_size: Number of records to return, defaults to 50

        :returns: Page of InsightsConversationsInstance
        :rtype: twilio.rest.flex_api.v1.insights_conversations.InsightsConversationsPage
        """
        data = values.of(
            {
                "Token": token,
                "SegmentId": segment_id,
                "PageToken": page_token,
                "Page": page_number,
                "PageSize": page_size,
            }
        )

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

    def get_page(self, target_url):
        """
        Retrieve a specific page of InsightsConversationsInstance records from the API.
        Request is executed immediately

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

        :returns: Page of InsightsConversationsInstance
        :rtype: twilio.rest.flex_api.v1.insights_conversations.InsightsConversationsPage
        """
        response = self._version.domain.twilio.request("GET", target_url)
        return InsightsConversationsPage(self._version, response)

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

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

        :returns: Page of InsightsConversationsInstance
        :rtype: twilio.rest.flex_api.v1.insights_conversations.InsightsConversationsPage
        """
        response = await self._version.domain.twilio.request_async("GET", target_url)
        return InsightsConversationsPage(self._version, response)

    def __repr__(self):
        """
        Provide a friendly representation

        :returns: Machine friendly representation
        :rtype: str
        """
        return "<Twilio.FlexApi.V1.InsightsConversationsList>"
