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

    Twilio - Trunking
    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 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 RecordingInstance(InstanceResource):

    class RecordingMode(object):
        DO_NOT_RECORD = "do-not-record"
        RECORD_FROM_RINGING = "record-from-ringing"
        RECORD_FROM_ANSWER = "record-from-answer"
        RECORD_FROM_RINGING_DUAL = "record-from-ringing-dual"
        RECORD_FROM_ANSWER_DUAL = "record-from-answer-dual"

    class RecordingTrim(object):
        TRIM_SILENCE = "trim-silence"
        DO_NOT_TRIM = "do-not-trim"

    """
    :ivar mode: 
    :ivar trim: 
    """

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

        self.mode: Optional["RecordingInstance.RecordingMode"] = payload.get("mode")
        self.trim: Optional["RecordingInstance.RecordingTrim"] = payload.get("trim")

        self._solution = {
            "trunk_sid": trunk_sid,
        }
        self._context: Optional[RecordingContext] = None

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

        :returns: RecordingContext for this RecordingInstance
        """
        if self._context is None:
            self._context = RecordingContext(
                self._version,
                trunk_sid=self._solution["trunk_sid"],
            )
        return self._context

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


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

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


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

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


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

    def update(
        self,
        mode: Union["RecordingInstance.RecordingMode", object] = values.unset,
        trim: Union["RecordingInstance.RecordingTrim", object] = values.unset,
    ) -> "RecordingInstance":
        """
        Update the RecordingInstance

        :param mode:
        :param trim:

        :returns: The updated RecordingInstance
        """
        return self._proxy.update(
            mode=mode,
            trim=trim,
        )

    async def update_async(
        self,
        mode: Union["RecordingInstance.RecordingMode", object] = values.unset,
        trim: Union["RecordingInstance.RecordingTrim", object] = values.unset,
    ) -> "RecordingInstance":
        """
        Asynchronous coroutine to update the RecordingInstance

        :param mode:
        :param trim:

        :returns: The updated RecordingInstance
        """
        return await self._proxy.update_async(
            mode=mode,
            trim=trim,
        )

    def update_with_http_info(
        self,
        mode: Union["RecordingInstance.RecordingMode", object] = values.unset,
        trim: Union["RecordingInstance.RecordingTrim", object] = values.unset,
    ) -> ApiResponse:
        """
        Update the RecordingInstance with HTTP info

        :param mode:
        :param trim:

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

    async def update_with_http_info_async(
        self,
        mode: Union["RecordingInstance.RecordingMode", object] = values.unset,
        trim: Union["RecordingInstance.RecordingTrim", object] = values.unset,
    ) -> ApiResponse:
        """
        Asynchronous coroutine to update the RecordingInstance with HTTP info

        :param mode:
        :param trim:

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

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


class RecordingContext(InstanceContext):

    def __init__(self, version: Version, trunk_sid: str):
        """
        Initialize the RecordingContext

        :param version: Version that contains the resource
        :param trunk_sid: The SID of the Trunk that will have its recording settings updated.
        """
        super().__init__(version)

        # Path Solution
        self._solution = {
            "trunk_sid": trunk_sid,
        }
        self._uri = "/Trunks/{trunk_sid}/Recording".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) -> RecordingInstance:
        """
        Fetch the RecordingInstance


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

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


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


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

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


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

    def _update(
        self,
        mode: Union["RecordingInstance.RecordingMode", object] = values.unset,
        trim: Union["RecordingInstance.RecordingTrim", object] = values.unset,
    ) -> tuple:
        """
        Internal helper for update operation

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

        data = values.of(
            {
                "Mode": mode,
                "Trim": trim,
            }
        )
        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,
        mode: Union["RecordingInstance.RecordingMode", object] = values.unset,
        trim: Union["RecordingInstance.RecordingTrim", object] = values.unset,
    ) -> RecordingInstance:
        """
        Update the RecordingInstance

        :param mode:
        :param trim:

        :returns: The updated RecordingInstance
        """
        payload, _, _ = self._update(mode=mode, trim=trim)
        return RecordingInstance(
            self._version, payload, trunk_sid=self._solution["trunk_sid"]
        )

    def update_with_http_info(
        self,
        mode: Union["RecordingInstance.RecordingMode", object] = values.unset,
        trim: Union["RecordingInstance.RecordingTrim", object] = values.unset,
    ) -> ApiResponse:
        """
        Update the RecordingInstance and return response metadata

        :param mode:
        :param trim:

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = self._update(mode=mode, trim=trim)
        instance = RecordingInstance(
            self._version, payload, trunk_sid=self._solution["trunk_sid"]
        )
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

    async def _update_async(
        self,
        mode: Union["RecordingInstance.RecordingMode", object] = values.unset,
        trim: Union["RecordingInstance.RecordingTrim", object] = values.unset,
    ) -> tuple:
        """
        Internal async helper for update operation

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

        data = values.of(
            {
                "Mode": mode,
                "Trim": trim,
            }
        )
        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,
        mode: Union["RecordingInstance.RecordingMode", object] = values.unset,
        trim: Union["RecordingInstance.RecordingTrim", object] = values.unset,
    ) -> RecordingInstance:
        """
        Asynchronous coroutine to update the RecordingInstance

        :param mode:
        :param trim:

        :returns: The updated RecordingInstance
        """
        payload, _, _ = await self._update_async(mode=mode, trim=trim)
        return RecordingInstance(
            self._version, payload, trunk_sid=self._solution["trunk_sid"]
        )

    async def update_with_http_info_async(
        self,
        mode: Union["RecordingInstance.RecordingMode", object] = values.unset,
        trim: Union["RecordingInstance.RecordingTrim", object] = values.unset,
    ) -> ApiResponse:
        """
        Asynchronous coroutine to update the RecordingInstance and return response metadata

        :param mode:
        :param trim:

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = await self._update_async(mode=mode, trim=trim)
        instance = RecordingInstance(
            self._version, payload, trunk_sid=self._solution["trunk_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.Trunking.V1.RecordingContext {}>".format(context)


class RecordingList(ListResource):

    def __init__(self, version: Version, trunk_sid: str):
        """
        Initialize the RecordingList

        :param version: Version that contains the resource
        :param trunk_sid: The SID of the Trunk from which to fetch the recording settings.

        """
        super().__init__(version)

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

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

        """
        return RecordingContext(self._version, trunk_sid=self._solution["trunk_sid"])

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

        """
        return RecordingContext(self._version, trunk_sid=self._solution["trunk_sid"])

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

        :returns: Machine friendly representation
        """
        return "<Twilio.Trunking.V1.RecordingList>"
