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, Optional, Union
from twilio.base import deserialize, 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 CreateFlexInstanceInstance(InstanceResource):

    class CreateInstanceRequestBody(object):
        """
        :ivar conversation:
        """

        def __init__(self, payload: Dict[str, Any]):

            self.conversation: Optional[
                CreateFlexInstanceList.CreateInstanceRequestBodyConversation
            ] = payload.get("conversation")

        def to_dict(self):
            return {
                "conversation": (
                    self.conversation.to_dict()
                    if self.conversation is not None
                    else None
                ),
            }

    class CreateInstanceRequestBodyConversation(object):
        """
        :ivar default: Set newly created conversation service as the default conversation service
        """

        def __init__(self, payload: Dict[str, Any]):

            self.default: Optional[bool] = payload.get("default")

        def to_dict(self):
            return {
                "default": self.default,
            }

    """
    :ivar flex_instance_sid: 
    :ivar account_sid: 
    :ivar status: 
    :ivar date_created: 
    :ivar date_updated: 
    """

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

        self.flex_instance_sid: Optional[str] = payload.get("flex_instance_sid")
        self.account_sid: Optional[str] = payload.get("account_sid")
        self.status: Optional[str] = payload.get("status")
        self.date_created: Optional[datetime] = deserialize.iso8601_datetime(
            payload.get("date_created")
        )
        self.date_updated: Optional[datetime] = deserialize.iso8601_datetime(
            payload.get("date_updated")
        )

        self._context: Optional[CreateFlexInstanceContext] = None

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

        :returns: CreateFlexInstanceContext for this CreateFlexInstanceInstance
        """
        if self._context is None:
            self._context = CreateFlexInstanceContext(
                self._version,
            )
        return self._context

    def create(
        self,
        create_instance_request_body: Union[
            CreateInstanceRequestBody, object
        ] = values.unset,
    ) -> "CreateFlexInstanceInstance":
        """
        Create the CreateFlexInstanceInstance

        :param create_instance_request_body:

        :returns: The created CreateFlexInstanceInstance
        """
        return self._proxy.create(
            create_instance_request_body=create_instance_request_body,
        )

    async def create_async(
        self,
        create_instance_request_body: Union[
            CreateInstanceRequestBody, object
        ] = values.unset,
    ) -> "CreateFlexInstanceInstance":
        """
        Asynchronous coroutine to create the CreateFlexInstanceInstance

        :param create_instance_request_body:

        :returns: The created CreateFlexInstanceInstance
        """
        return await self._proxy.create_async(
            create_instance_request_body=create_instance_request_body,
        )

    def create_with_http_info(
        self,
        create_instance_request_body: Union[
            CreateInstanceRequestBody, object
        ] = values.unset,
    ) -> ApiResponse:
        """
        Create the CreateFlexInstanceInstance with HTTP info

        :param create_instance_request_body:

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

    async def create_with_http_info_async(
        self,
        create_instance_request_body: Union[
            CreateInstanceRequestBody, object
        ] = values.unset,
    ) -> ApiResponse:
        """
        Asynchronous coroutine to create the CreateFlexInstanceInstance with HTTP info

        :param create_instance_request_body:

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

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

        :returns: Machine friendly representation
        """

        return "<Twilio.FlexApi.V1.CreateFlexInstanceInstance>"


class CreateFlexInstanceContext(InstanceContext):

    class CreateInstanceRequestBody(object):
        """
        :ivar conversation:
        """

        def __init__(self, payload: Dict[str, Any]):

            self.conversation: Optional[
                CreateFlexInstanceList.CreateInstanceRequestBodyConversation
            ] = payload.get("conversation")

        def to_dict(self):
            return {
                "conversation": (
                    self.conversation.to_dict()
                    if self.conversation is not None
                    else None
                ),
            }

    class CreateInstanceRequestBodyConversation(object):
        """
        :ivar default: Set newly created conversation service as the default conversation service
        """

        def __init__(self, payload: Dict[str, Any]):

            self.default: Optional[bool] = payload.get("default")

        def to_dict(self):
            return {
                "default": self.default,
            }

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

        :param version: Version that contains the resource
        """
        super().__init__(version)

        self._uri = "/Instances"

    def _create(
        self,
        create_instance_request_body: Union[
            CreateInstanceRequestBody, object
        ] = values.unset,
    ) -> tuple:
        """
        Internal helper for create operation

        Returns:
            tuple: (payload, status_code, headers)
        """
        data = create_instance_request_body.to_dict()

        headers = values.of({})

        headers["Content-Type"] = "application/json"

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

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

    def create(
        self,
        create_instance_request_body: Union[
            CreateInstanceRequestBody, object
        ] = values.unset,
    ) -> CreateFlexInstanceInstance:
        """
        Create the CreateFlexInstanceInstance

        :param create_instance_request_body:

        :returns: The created CreateFlexInstanceInstance
        """
        payload, _, _ = self._create(
            create_instance_request_body=create_instance_request_body
        )
        return CreateFlexInstanceInstance(self._version, payload)

    def create_with_http_info(
        self,
        create_instance_request_body: Union[
            CreateInstanceRequestBody, object
        ] = values.unset,
    ) -> ApiResponse:
        """
        Create the CreateFlexInstanceInstance and return response metadata

        :param create_instance_request_body:

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = self._create(
            create_instance_request_body=create_instance_request_body
        )
        instance = CreateFlexInstanceInstance(self._version, payload)
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

    async def _create_async(
        self,
        create_instance_request_body: Union[
            CreateInstanceRequestBody, object
        ] = values.unset,
    ) -> tuple:
        """
        Internal async helper for create operation

        Returns:
            tuple: (payload, status_code, headers)
        """
        data = create_instance_request_body.to_dict()

        headers = values.of({})

        headers["Content-Type"] = "application/json"

        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,
        create_instance_request_body: Union[
            CreateInstanceRequestBody, object
        ] = values.unset,
    ) -> CreateFlexInstanceInstance:
        """
        Asynchronous coroutine to create the CreateFlexInstanceInstance

        :param create_instance_request_body:

        :returns: The created CreateFlexInstanceInstance
        """
        payload, _, _ = await self._create_async(
            create_instance_request_body=create_instance_request_body
        )
        return CreateFlexInstanceInstance(self._version, payload)

    async def create_with_http_info_async(
        self,
        create_instance_request_body: Union[
            CreateInstanceRequestBody, object
        ] = values.unset,
    ) -> ApiResponse:
        """
        Asynchronous coroutine to create the CreateFlexInstanceInstance and return response metadata

        :param create_instance_request_body:

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = await self._create_async(
            create_instance_request_body=create_instance_request_body
        )
        instance = CreateFlexInstanceInstance(self._version, payload)
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

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

        :returns: Machine friendly representation
        """

        return "<Twilio.FlexApi.V1.CreateFlexInstanceContext>"


class CreateFlexInstanceList(ListResource):

    class CreateInstanceRequestBody(object):
        """
        :ivar conversation:
        """

        def __init__(self, payload: Dict[str, Any]):

            self.conversation: Optional[
                CreateFlexInstanceList.CreateInstanceRequestBodyConversation
            ] = payload.get("conversation")

        def to_dict(self):
            return {
                "conversation": (
                    self.conversation.to_dict()
                    if self.conversation is not None
                    else None
                ),
            }

    class CreateInstanceRequestBodyConversation(object):
        """
        :ivar default: Set newly created conversation service as the default conversation service
        """

        def __init__(self, payload: Dict[str, Any]):

            self.default: Optional[bool] = payload.get("default")

        def to_dict(self):
            return {
                "default": self.default,
            }

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

        :param version: Version that contains the resource

        """
        super().__init__(version)

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

        """
        return CreateFlexInstanceContext(self._version)

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

        """
        return CreateFlexInstanceContext(self._version)

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

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