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

    Twilio - Bulkexports
    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, Optional, Union
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 ExportConfigurationInstance(InstanceResource):
    """
    :ivar enabled: If true, Twilio will automatically generate every day's file when the day is over.
    :ivar webhook_url: Stores the URL destination for the method specified in webhook_method.
    :ivar webhook_method: Sets whether Twilio should call a webhook URL when the automatic generation is complete, using GET or POST. The actual destination is set in the webhook_url
    :ivar resource_type: The type of communication – Messages, Calls, Conferences, and Participants
    :ivar url: The URL of this resource.
    """

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

        self.enabled: Optional[bool] = payload.get("enabled")
        self.webhook_url: Optional[str] = payload.get("webhook_url")
        self.webhook_method: Optional[str] = payload.get("webhook_method")
        self.resource_type: Optional[str] = payload.get("resource_type")
        self.url: Optional[str] = payload.get("url")

        self._solution = {
            "resource_type": resource_type or self.resource_type,
        }
        self._context: Optional[ExportConfigurationContext] = None

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

        :returns: ExportConfigurationContext for this ExportConfigurationInstance
        """
        if self._context is None:
            self._context = ExportConfigurationContext(
                self._version,
                resource_type=self._solution["resource_type"],
            )
        return self._context

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


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

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


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

    def fetch_with_http_info(self) -> ApiResponse:
        """
        Fetch the ExportConfigurationInstance 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 ExportConfigurationInstance with HTTP info


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

    def update(
        self,
        enabled: Union[bool, object] = values.unset,
        webhook_url: Union[str, object] = values.unset,
        webhook_method: Union[str, object] = values.unset,
    ) -> "ExportConfigurationInstance":
        """
        Update the ExportConfigurationInstance

        :param enabled: If true, Twilio will automatically generate every day's file when the day is over.
        :param webhook_url: Stores the URL destination for the method specified in webhook_method.
        :param webhook_method: Sets whether Twilio should call a webhook URL when the automatic generation is complete, using GET or POST. The actual destination is set in the webhook_url

        :returns: The updated ExportConfigurationInstance
        """
        return self._proxy.update(
            enabled=enabled,
            webhook_url=webhook_url,
            webhook_method=webhook_method,
        )

    async def update_async(
        self,
        enabled: Union[bool, object] = values.unset,
        webhook_url: Union[str, object] = values.unset,
        webhook_method: Union[str, object] = values.unset,
    ) -> "ExportConfigurationInstance":
        """
        Asynchronous coroutine to update the ExportConfigurationInstance

        :param enabled: If true, Twilio will automatically generate every day's file when the day is over.
        :param webhook_url: Stores the URL destination for the method specified in webhook_method.
        :param webhook_method: Sets whether Twilio should call a webhook URL when the automatic generation is complete, using GET or POST. The actual destination is set in the webhook_url

        :returns: The updated ExportConfigurationInstance
        """
        return await self._proxy.update_async(
            enabled=enabled,
            webhook_url=webhook_url,
            webhook_method=webhook_method,
        )

    def update_with_http_info(
        self,
        enabled: Union[bool, object] = values.unset,
        webhook_url: Union[str, object] = values.unset,
        webhook_method: Union[str, object] = values.unset,
    ) -> ApiResponse:
        """
        Update the ExportConfigurationInstance with HTTP info

        :param enabled: If true, Twilio will automatically generate every day's file when the day is over.
        :param webhook_url: Stores the URL destination for the method specified in webhook_method.
        :param webhook_method: Sets whether Twilio should call a webhook URL when the automatic generation is complete, using GET or POST. The actual destination is set in the webhook_url

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

    async def update_with_http_info_async(
        self,
        enabled: Union[bool, object] = values.unset,
        webhook_url: Union[str, object] = values.unset,
        webhook_method: Union[str, object] = values.unset,
    ) -> ApiResponse:
        """
        Asynchronous coroutine to update the ExportConfigurationInstance with HTTP info

        :param enabled: If true, Twilio will automatically generate every day's file when the day is over.
        :param webhook_url: Stores the URL destination for the method specified in webhook_method.
        :param webhook_method: Sets whether Twilio should call a webhook URL when the automatic generation is complete, using GET or POST. The actual destination is set in the webhook_url

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

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


class ExportConfigurationContext(InstanceContext):

    def __init__(self, version: Version, resource_type: str):
        """
        Initialize the ExportConfigurationContext

        :param version: Version that contains the resource
        :param resource_type: The type of communication – Messages, Calls, Conferences, and Participants
        """
        super().__init__(version)

        # Path Solution
        self._solution = {
            "resource_type": resource_type,
        }
        self._uri = "/Exports/{resource_type}/Configuration".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) -> ExportConfigurationInstance:
        """
        Fetch the ExportConfigurationInstance


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

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


        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = self._fetch()
        instance = ExportConfigurationInstance(
            self._version,
            payload,
            resource_type=self._solution["resource_type"],
        )
        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) -> ExportConfigurationInstance:
        """
        Asynchronous coroutine to fetch the ExportConfigurationInstance


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

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


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

    def _update(
        self,
        enabled: Union[bool, object] = values.unset,
        webhook_url: Union[str, object] = values.unset,
        webhook_method: Union[str, object] = values.unset,
    ) -> tuple:
        """
        Internal helper for update operation

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

        data = values.of(
            {
                "Enabled": serialize.boolean_to_string(enabled),
                "WebhookUrl": webhook_url,
                "WebhookMethod": webhook_method,
            }
        )
        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,
        enabled: Union[bool, object] = values.unset,
        webhook_url: Union[str, object] = values.unset,
        webhook_method: Union[str, object] = values.unset,
    ) -> ExportConfigurationInstance:
        """
        Update the ExportConfigurationInstance

        :param enabled: If true, Twilio will automatically generate every day's file when the day is over.
        :param webhook_url: Stores the URL destination for the method specified in webhook_method.
        :param webhook_method: Sets whether Twilio should call a webhook URL when the automatic generation is complete, using GET or POST. The actual destination is set in the webhook_url

        :returns: The updated ExportConfigurationInstance
        """
        payload, _, _ = self._update(
            enabled=enabled, webhook_url=webhook_url, webhook_method=webhook_method
        )
        return ExportConfigurationInstance(
            self._version, payload, resource_type=self._solution["resource_type"]
        )

    def update_with_http_info(
        self,
        enabled: Union[bool, object] = values.unset,
        webhook_url: Union[str, object] = values.unset,
        webhook_method: Union[str, object] = values.unset,
    ) -> ApiResponse:
        """
        Update the ExportConfigurationInstance and return response metadata

        :param enabled: If true, Twilio will automatically generate every day's file when the day is over.
        :param webhook_url: Stores the URL destination for the method specified in webhook_method.
        :param webhook_method: Sets whether Twilio should call a webhook URL when the automatic generation is complete, using GET or POST. The actual destination is set in the webhook_url

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = self._update(
            enabled=enabled, webhook_url=webhook_url, webhook_method=webhook_method
        )
        instance = ExportConfigurationInstance(
            self._version, payload, resource_type=self._solution["resource_type"]
        )
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

    async def _update_async(
        self,
        enabled: Union[bool, object] = values.unset,
        webhook_url: Union[str, object] = values.unset,
        webhook_method: Union[str, object] = values.unset,
    ) -> tuple:
        """
        Internal async helper for update operation

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

        data = values.of(
            {
                "Enabled": serialize.boolean_to_string(enabled),
                "WebhookUrl": webhook_url,
                "WebhookMethod": webhook_method,
            }
        )
        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,
        enabled: Union[bool, object] = values.unset,
        webhook_url: Union[str, object] = values.unset,
        webhook_method: Union[str, object] = values.unset,
    ) -> ExportConfigurationInstance:
        """
        Asynchronous coroutine to update the ExportConfigurationInstance

        :param enabled: If true, Twilio will automatically generate every day's file when the day is over.
        :param webhook_url: Stores the URL destination for the method specified in webhook_method.
        :param webhook_method: Sets whether Twilio should call a webhook URL when the automatic generation is complete, using GET or POST. The actual destination is set in the webhook_url

        :returns: The updated ExportConfigurationInstance
        """
        payload, _, _ = await self._update_async(
            enabled=enabled, webhook_url=webhook_url, webhook_method=webhook_method
        )
        return ExportConfigurationInstance(
            self._version, payload, resource_type=self._solution["resource_type"]
        )

    async def update_with_http_info_async(
        self,
        enabled: Union[bool, object] = values.unset,
        webhook_url: Union[str, object] = values.unset,
        webhook_method: Union[str, object] = values.unset,
    ) -> ApiResponse:
        """
        Asynchronous coroutine to update the ExportConfigurationInstance and return response metadata

        :param enabled: If true, Twilio will automatically generate every day's file when the day is over.
        :param webhook_url: Stores the URL destination for the method specified in webhook_method.
        :param webhook_method: Sets whether Twilio should call a webhook URL when the automatic generation is complete, using GET or POST. The actual destination is set in the webhook_url

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = await self._update_async(
            enabled=enabled, webhook_url=webhook_url, webhook_method=webhook_method
        )
        instance = ExportConfigurationInstance(
            self._version, payload, resource_type=self._solution["resource_type"]
        )
        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.Bulkexports.V1.ExportConfigurationContext {}>".format(context)


class ExportConfigurationList(ListResource):

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

        :param version: Version that contains the resource

        """
        super().__init__(version)

    def get(self, resource_type: str) -> ExportConfigurationContext:
        """
        Constructs a ExportConfigurationContext

        :param resource_type: The type of communication – Messages, Calls, Conferences, and Participants
        """
        return ExportConfigurationContext(self._version, resource_type=resource_type)

    def __call__(self, resource_type: str) -> ExportConfigurationContext:
        """
        Constructs a ExportConfigurationContext

        :param resource_type: The type of communication – Messages, Calls, Conferences, and Participants
        """
        return ExportConfigurationContext(self._version, resource_type=resource_type)

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

        :returns: Machine friendly representation
        """
        return "<Twilio.Bulkexports.V1.ExportConfigurationList>"
