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 Any, Dict, List, Optional
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


class FlowTestUserInstance(InstanceResource):
    """
    :ivar sid: Unique identifier of the flow.
    :ivar test_users: List of test user identities that can test draft versions of the flow.
    :ivar url: The URL of this resource.
    """

    def __init__(self, version: Version, payload: Dict[str, Any], sid: str):
        super().__init__(version)

        self.sid: Optional[str] = payload.get("sid")
        self.test_users: Optional[List[str]] = payload.get("test_users")
        self.url: Optional[str] = payload.get("url")

        self._solution = {
            "sid": sid,
        }
        self._context: Optional[FlowTestUserContext] = None

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

        :returns: FlowTestUserContext for this FlowTestUserInstance
        """
        if self._context is None:
            self._context = FlowTestUserContext(
                self._version,
                sid=self._solution["sid"],
            )
        return self._context

    def fetch(self) -> "FlowTestUserInstance":
        """
        Fetch the FlowTestUserInstance


        :returns: The fetched FlowTestUserInstance
        """
        return self._proxy.fetch()

    async def fetch_async(self) -> "FlowTestUserInstance":
        """
        Asynchronous coroutine to fetch the FlowTestUserInstance


        :returns: The fetched FlowTestUserInstance
        """
        return await self._proxy.fetch_async()

    def fetch_with_http_info(self) -> ApiResponse:
        """
        Fetch the FlowTestUserInstance with HTTP info


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

    async def fetch_with_http_info_async(self) -> ApiResponse:
        """
        Asynchronous coroutine to fetch the FlowTestUserInstance with HTTP info


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

    def update(self, test_users: List[str]) -> "FlowTestUserInstance":
        """
        Update the FlowTestUserInstance

        :param test_users: List of test user identities that can test draft versions of the flow.

        :returns: The updated FlowTestUserInstance
        """
        return self._proxy.update(
            test_users=test_users,
        )

    async def update_async(self, test_users: List[str]) -> "FlowTestUserInstance":
        """
        Asynchronous coroutine to update the FlowTestUserInstance

        :param test_users: List of test user identities that can test draft versions of the flow.

        :returns: The updated FlowTestUserInstance
        """
        return await self._proxy.update_async(
            test_users=test_users,
        )

    def update_with_http_info(self, test_users: List[str]) -> ApiResponse:
        """
        Update the FlowTestUserInstance with HTTP info

        :param test_users: List of test user identities that can test draft versions of the flow.

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

    async def update_with_http_info_async(self, test_users: List[str]) -> ApiResponse:
        """
        Asynchronous coroutine to update the FlowTestUserInstance with HTTP info

        :param test_users: List of test user identities that can test draft versions of the flow.

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

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


class FlowTestUserContext(InstanceContext):

    def __init__(self, version: Version, sid: str):
        """
        Initialize the FlowTestUserContext

        :param version: Version that contains the resource
        :param sid: Unique identifier of the flow.
        """
        super().__init__(version)

        # Path Solution
        self._solution = {
            "sid": sid,
        }
        self._uri = "/Flows/{sid}/TestUsers".format(**self._solution)

    def _fetch(self) -> tuple:
        """
        Internal helper for fetch operation

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

        headers = values.of({})

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

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

    def fetch(self) -> FlowTestUserInstance:
        """
        Fetch the FlowTestUserInstance


        :returns: The fetched FlowTestUserInstance
        """
        payload, _, _ = self._fetch()
        return FlowTestUserInstance(
            self._version,
            payload,
            sid=self._solution["sid"],
        )

    def fetch_with_http_info(self) -> ApiResponse:
        """
        Fetch the FlowTestUserInstance and return response metadata


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

    async def _fetch_async(self) -> tuple:
        """
        Internal async helper for fetch operation

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

        headers = values.of({})

        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) -> FlowTestUserInstance:
        """
        Asynchronous coroutine to fetch the FlowTestUserInstance


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

    async def fetch_with_http_info_async(self) -> ApiResponse:
        """
        Asynchronous coroutine to fetch the FlowTestUserInstance and return response metadata


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

    def _update(self, test_users: List[str]) -> tuple:
        """
        Internal helper for update operation

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

        data = values.of(
            {
                "TestUsers": serialize.map(test_users, lambda e: e),
            }
        )
        headers = values.of({})

        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, test_users: List[str]) -> FlowTestUserInstance:
        """
        Update the FlowTestUserInstance

        :param test_users: List of test user identities that can test draft versions of the flow.

        :returns: The updated FlowTestUserInstance
        """
        payload, _, _ = self._update(test_users=test_users)
        return FlowTestUserInstance(self._version, payload, sid=self._solution["sid"])

    def update_with_http_info(self, test_users: List[str]) -> ApiResponse:
        """
        Update the FlowTestUserInstance and return response metadata

        :param test_users: List of test user identities that can test draft versions of the flow.

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = self._update(test_users=test_users)
        instance = FlowTestUserInstance(
            self._version, payload, sid=self._solution["sid"]
        )
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

    async def _update_async(self, test_users: List[str]) -> tuple:
        """
        Internal async helper for update operation

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

        data = values.of(
            {
                "TestUsers": serialize.map(test_users, lambda e: e),
            }
        )
        headers = values.of({})

        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, test_users: List[str]) -> FlowTestUserInstance:
        """
        Asynchronous coroutine to update the FlowTestUserInstance

        :param test_users: List of test user identities that can test draft versions of the flow.

        :returns: The updated FlowTestUserInstance
        """
        payload, _, _ = await self._update_async(test_users=test_users)
        return FlowTestUserInstance(self._version, payload, sid=self._solution["sid"])

    async def update_with_http_info_async(self, test_users: List[str]) -> ApiResponse:
        """
        Asynchronous coroutine to update the FlowTestUserInstance and return response metadata

        :param test_users: List of test user identities that can test draft versions of the flow.

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = await self._update_async(test_users=test_users)
        instance = FlowTestUserInstance(
            self._version, payload, sid=self._solution["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.Studio.V2.FlowTestUserContext {}>".format(context)


class FlowTestUserList(ListResource):

    def __init__(self, version: Version, sid: str):
        """
        Initialize the FlowTestUserList

        :param version: Version that contains the resource
        :param sid: Unique identifier of the flow.

        """
        super().__init__(version)

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

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

        """
        return FlowTestUserContext(self._version, sid=self._solution["sid"])

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

        """
        return FlowTestUserContext(self._version, sid=self._solution["sid"])

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

        :returns: Machine friendly representation
        """
        return "<Twilio.Studio.V2.FlowTestUserList>"
