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

    Twilio - Studio
    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 Optional
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 EngagementContextInstance(InstanceResource):
    def __init__(self, version, payload, flow_sid: str, engagement_sid: str):
        """
        Initialize the EngagementContextInstance

        :returns: twilio.rest.studio.v1.flow.engagement.engagement_context.EngagementContextInstance
        :rtype: twilio.rest.studio.v1.flow.engagement.engagement_context.EngagementContextInstance
        """
        super().__init__(version)

        self._properties = {
            "account_sid": payload.get("account_sid"),
            "context": payload.get("context"),
            "engagement_sid": payload.get("engagement_sid"),
            "flow_sid": payload.get("flow_sid"),
            "url": payload.get("url"),
        }

        self._solution = {
            "flow_sid": flow_sid,
            "engagement_sid": engagement_sid,
        }
        self._context: Optional[EngagementContextContext] = None

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

        :returns: EngagementContextContext for this EngagementContextInstance
        :rtype: twilio.rest.studio.v1.flow.engagement.engagement_context.EngagementContextContext
        """
        if self._context is None:
            self._context = EngagementContextContext(
                self._version,
                flow_sid=self._solution["flow_sid"],
                engagement_sid=self._solution["engagement_sid"],
            )
        return self._context

    @property
    def account_sid(self):
        """
        :returns: The SID of the Account.
        :rtype: str
        """
        return self._properties["account_sid"]

    @property
    def context(self):
        """
        :returns: As your flow executes, we save the state in what's called the Flow Context. Any data in the flow context can be accessed by your widgets as variables, either in configuration fields or in text areas as variable substitution.
        :rtype: dict
        """
        return self._properties["context"]

    @property
    def engagement_sid(self):
        """
        :returns: The SID of the Engagement.
        :rtype: str
        """
        return self._properties["engagement_sid"]

    @property
    def flow_sid(self):
        """
        :returns: The SID of the Flow.
        :rtype: str
        """
        return self._properties["flow_sid"]

    @property
    def url(self):
        """
        :returns: The URL of the resource.
        :rtype: str
        """
        return self._properties["url"]

    def fetch(self):
        """
        Fetch the EngagementContextInstance


        :returns: The fetched EngagementContextInstance
        :rtype: twilio.rest.studio.v1.flow.engagement.engagement_context.EngagementContextInstance
        """
        return self._proxy.fetch()

    async def fetch_async(self):
        """
        Asynchronous coroutine to fetch the EngagementContextInstance


        :returns: The fetched EngagementContextInstance
        :rtype: twilio.rest.studio.v1.flow.engagement.engagement_context.EngagementContextInstance
        """
        return await self._proxy.fetch_async()

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


class EngagementContextContext(InstanceContext):
    def __init__(self, version: Version, flow_sid: str, engagement_sid: str):
        """
        Initialize the EngagementContextContext

        :param Version version: Version that contains the resource
        :param flow_sid: The SID of the Flow.
        :param engagement_sid: The SID of the Engagement.

        :returns: twilio.rest.studio.v1.flow.engagement.engagement_context.EngagementContextContext
        :rtype: twilio.rest.studio.v1.flow.engagement.engagement_context.EngagementContextContext
        """
        super().__init__(version)

        # Path Solution
        self._solution = {
            "flow_sid": flow_sid,
            "engagement_sid": engagement_sid,
        }
        self._uri = "/Flows/{flow_sid}/Engagements/{engagement_sid}/Context".format(
            **self._solution
        )

    def fetch(self):
        """
        Fetch the EngagementContextInstance


        :returns: The fetched EngagementContextInstance
        :rtype: twilio.rest.studio.v1.flow.engagement.engagement_context.EngagementContextInstance
        """

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

        return EngagementContextInstance(
            self._version,
            payload,
            flow_sid=self._solution["flow_sid"],
            engagement_sid=self._solution["engagement_sid"],
        )

    async def fetch_async(self):
        """
        Asynchronous coroutine to fetch the EngagementContextInstance


        :returns: The fetched EngagementContextInstance
        :rtype: twilio.rest.studio.v1.flow.engagement.engagement_context.EngagementContextInstance
        """

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

        return EngagementContextInstance(
            self._version,
            payload,
            flow_sid=self._solution["flow_sid"],
            engagement_sid=self._solution["engagement_sid"],
        )

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


class EngagementContextList(ListResource):
    def __init__(self, version: Version, flow_sid: str, engagement_sid: str):
        """
        Initialize the EngagementContextList

        :param Version version: Version that contains the resource
        :param flow_sid: The SID of the Flow.
        :param engagement_sid: The SID of the Engagement.

        :returns: twilio.rest.studio.v1.flow.engagement.engagement_context.EngagementContextList
        :rtype: twilio.rest.studio.v1.flow.engagement.engagement_context.EngagementContextList
        """
        super().__init__(version)

        # Path Solution
        self._solution = {
            "flow_sid": flow_sid,
            "engagement_sid": engagement_sid,
        }

    def get(self):
        """
        Constructs a EngagementContextContext


        :returns: twilio.rest.studio.v1.flow.engagement.engagement_context.EngagementContextContext
        :rtype: twilio.rest.studio.v1.flow.engagement.engagement_context.EngagementContextContext
        """
        return EngagementContextContext(
            self._version,
            flow_sid=self._solution["flow_sid"],
            engagement_sid=self._solution["engagement_sid"],
        )

    def __call__(self):
        """
        Constructs a EngagementContextContext


        :returns: twilio.rest.studio.v1.flow.engagement.engagement_context.EngagementContextContext
        :rtype: twilio.rest.studio.v1.flow.engagement.engagement_context.EngagementContextContext
        """
        return EngagementContextContext(
            self._version,
            flow_sid=self._solution["flow_sid"],
            engagement_sid=self._solution["engagement_sid"],
        )

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

        :returns: Machine friendly representation
        :rtype: str
        """
        return "<Twilio.Studio.V1.EngagementContextList>"
