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 datetime import datetime
from typing import Any, Dict, List, Optional, Union
from twilio.base import deserialize, serialize, values
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 InsightsConversationalAiReportInsightsInstance(InstanceResource):
    """
    :ivar instance_sid: The Instance SID of the instance for which report insights is fetched
    :ivar report_id: The type of report insights required to fetch.Like gauge,channel-metrics,queue-metrics
    :ivar period_start: The start date from which report insights data is included
    :ivar period_end: The end date till report insights data is included
    :ivar updated: Updated time of the report insights
    :ivar insights: List of report insights breakdown
    :ivar url: The URL of this resource
    """

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

        self.instance_sid: Optional[str] = payload.get("instance_sid")
        self.report_id: Optional[str] = payload.get("report_id")
        self.period_start: Optional[datetime] = deserialize.iso8601_datetime(
            payload.get("period_start")
        )
        self.period_end: Optional[datetime] = deserialize.iso8601_datetime(
            payload.get("period_end")
        )
        self.updated: Optional[datetime] = deserialize.iso8601_datetime(
            payload.get("updated")
        )
        self.insights: Optional[List[Dict[str, object]]] = payload.get("insights")
        self.url: Optional[str] = payload.get("url")

        self._solution = {
            "instance_sid": instance_sid or self.instance_sid,
        }
        self._context: Optional[InsightsConversationalAiReportInsightsContext] = None

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

        :returns: InsightsConversationalAiReportInsightsContext for this InsightsConversationalAiReportInsightsInstance
        """
        if self._context is None:
            self._context = InsightsConversationalAiReportInsightsContext(
                self._version,
                instance_sid=self._solution["instance_sid"],
            )
        return self._context

    def fetch(
        self,
        max_rows: Union[int, object] = values.unset,
        report_id: Union[str, object] = values.unset,
        granularity: Union[str, object] = values.unset,
        include_date: Union[datetime, object] = values.unset,
    ) -> "InsightsConversationalAiReportInsightsInstance":
        """
        Fetch the InsightsConversationalAiReportInsightsInstance

        :param max_rows: Maximum number of rows to return
        :param report_id: The type of report insights required to fetch.Like gauge,channel-metrics,queue-metrics
        :param granularity: The time period for which report insights is needed
        :param include_date: A reference date that should be included in the returned period

        :returns: The fetched InsightsConversationalAiReportInsightsInstance
        """
        return self._proxy.fetch(
            max_rows=max_rows,
            report_id=report_id,
            granularity=granularity,
            include_date=include_date,
        )

    async def fetch_async(
        self,
        max_rows: Union[int, object] = values.unset,
        report_id: Union[str, object] = values.unset,
        granularity: Union[str, object] = values.unset,
        include_date: Union[datetime, object] = values.unset,
    ) -> "InsightsConversationalAiReportInsightsInstance":
        """
        Asynchronous coroutine to fetch the InsightsConversationalAiReportInsightsInstance

        :param max_rows: Maximum number of rows to return
        :param report_id: The type of report insights required to fetch.Like gauge,channel-metrics,queue-metrics
        :param granularity: The time period for which report insights is needed
        :param include_date: A reference date that should be included in the returned period

        :returns: The fetched InsightsConversationalAiReportInsightsInstance
        """
        return await self._proxy.fetch_async(
            max_rows=max_rows,
            report_id=report_id,
            granularity=granularity,
            include_date=include_date,
        )

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


class InsightsConversationalAiReportInsightsContext(InstanceContext):

    def __init__(self, version: Version, instance_sid: str):
        """
        Initialize the InsightsConversationalAiReportInsightsContext

        :param version: Version that contains the resource
        :param instance_sid: The Instance SID of the instance for which report insights will be fetched
        """
        super().__init__(version)

        # Path Solution
        self._solution = {
            "instance_sid": instance_sid,
        }
        self._uri = "/Insights/Instances/{instance_sid}/AI/ReportInsights".format(
            **self._solution
        )

    def fetch(
        self,
        max_rows: Union[int, object] = values.unset,
        report_id: Union[str, object] = values.unset,
        granularity: Union[str, object] = values.unset,
        include_date: Union[datetime, object] = values.unset,
    ) -> InsightsConversationalAiReportInsightsInstance:
        """
        Fetch the InsightsConversationalAiReportInsightsInstance

        :param max_rows: Maximum number of rows to return
        :param report_id: The type of report insights required to fetch.Like gauge,channel-metrics,queue-metrics
        :param granularity: The time period for which report insights is needed
        :param include_date: A reference date that should be included in the returned period

        :returns: The fetched InsightsConversationalAiReportInsightsInstance
        """

        data = values.of(
            {
                "MaxRows": max_rows,
                "ReportId": report_id,
                "Granularity": granularity,
                "IncludeDate": serialize.iso8601_datetime(include_date),
            }
        )

        payload = self._version.fetch(method="GET", uri=self._uri, params=data)

        return InsightsConversationalAiReportInsightsInstance(
            self._version,
            payload,
            instance_sid=self._solution["instance_sid"],
        )

    async def fetch_async(
        self,
        max_rows: Union[int, object] = values.unset,
        report_id: Union[str, object] = values.unset,
        granularity: Union[str, object] = values.unset,
        include_date: Union[datetime, object] = values.unset,
    ) -> InsightsConversationalAiReportInsightsInstance:
        """
        Asynchronous coroutine to fetch the InsightsConversationalAiReportInsightsInstance

        :param max_rows: Maximum number of rows to return
        :param report_id: The type of report insights required to fetch.Like gauge,channel-metrics,queue-metrics
        :param granularity: The time period for which report insights is needed
        :param include_date: A reference date that should be included in the returned period

        :returns: The fetched InsightsConversationalAiReportInsightsInstance
        """

        data = values.of(
            {
                "MaxRows": max_rows,
                "ReportId": report_id,
                "Granularity": granularity,
                "IncludeDate": serialize.iso8601_datetime(include_date),
            }
        )

        payload = await self._version.fetch_async(
            method="GET", uri=self._uri, params=data
        )

        return InsightsConversationalAiReportInsightsInstance(
            self._version,
            payload,
            instance_sid=self._solution["instance_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.FlexApi.V1.InsightsConversationalAiReportInsightsContext {}>".format(
            context
        )


class InsightsConversationalAiReportInsightsList(ListResource):

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

        :param version: Version that contains the resource

        """
        super().__init__(version)

    def get(self, instance_sid: str) -> InsightsConversationalAiReportInsightsContext:
        """
        Constructs a InsightsConversationalAiReportInsightsContext

        :param instance_sid: The Instance SID of the instance for which report insights will be fetched
        """
        return InsightsConversationalAiReportInsightsContext(
            self._version, instance_sid=instance_sid
        )

    def __call__(
        self, instance_sid: str
    ) -> InsightsConversationalAiReportInsightsContext:
        """
        Constructs a InsightsConversationalAiReportInsightsContext

        :param instance_sid: The Instance SID of the instance for which report insights will be fetched
        """
        return InsightsConversationalAiReportInsightsContext(
            self._version, instance_sid=instance_sid
        )

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

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