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

    Twilio - Routes
    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 SipDomainInstance(InstanceResource):
    """
    :ivar sip_domain:
    :ivar url:
    :ivar sid:
    :ivar account_sid:
    :ivar friendly_name:
    :ivar voice_region:
    :ivar date_created:
    :ivar date_updated:
    """

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

        self.sip_domain: Optional[str] = payload.get("sip_domain")
        self.url: Optional[str] = payload.get("url")
        self.sid: Optional[str] = payload.get("sid")
        self.account_sid: Optional[str] = payload.get("account_sid")
        self.friendly_name: Optional[str] = payload.get("friendly_name")
        self.voice_region: Optional[str] = payload.get("voice_region")
        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._solution = {
            "sip_domain": sip_domain or self.sip_domain,
        }
        self._context: Optional[SipDomainContext] = None

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

        :returns: SipDomainContext for this SipDomainInstance
        """
        if self._context is None:
            self._context = SipDomainContext(
                self._version,
                sip_domain=self._solution["sip_domain"],
            )
        return self._context

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


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

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


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

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


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

    def update(
        self,
        voice_region: Union[str, object] = values.unset,
        friendly_name: Union[str, object] = values.unset,
    ) -> "SipDomainInstance":
        """
        Update the SipDomainInstance

        :param voice_region:
        :param friendly_name:

        :returns: The updated SipDomainInstance
        """
        return self._proxy.update(
            voice_region=voice_region,
            friendly_name=friendly_name,
        )

    async def update_async(
        self,
        voice_region: Union[str, object] = values.unset,
        friendly_name: Union[str, object] = values.unset,
    ) -> "SipDomainInstance":
        """
        Asynchronous coroutine to update the SipDomainInstance

        :param voice_region:
        :param friendly_name:

        :returns: The updated SipDomainInstance
        """
        return await self._proxy.update_async(
            voice_region=voice_region,
            friendly_name=friendly_name,
        )

    def update_with_http_info(
        self,
        voice_region: Union[str, object] = values.unset,
        friendly_name: Union[str, object] = values.unset,
    ) -> ApiResponse:
        """
        Update the SipDomainInstance with HTTP info

        :param voice_region:
        :param friendly_name:

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

    async def update_with_http_info_async(
        self,
        voice_region: Union[str, object] = values.unset,
        friendly_name: Union[str, object] = values.unset,
    ) -> ApiResponse:
        """
        Asynchronous coroutine to update the SipDomainInstance with HTTP info

        :param voice_region:
        :param friendly_name:

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

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


class SipDomainContext(InstanceContext):

    def __init__(self, version: Version, sip_domain: str):
        """
        Initialize the SipDomainContext

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

        # Path Solution
        self._solution = {
            "sip_domain": sip_domain,
        }
        self._uri = "/SipDomains/{sip_domain}".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) -> SipDomainInstance:
        """
        Fetch the SipDomainInstance


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

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


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


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

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


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

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

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

        data = values.of(
            {
                "VoiceRegion": voice_region,
                "FriendlyName": friendly_name,
            }
        )
        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,
        voice_region: Union[str, object] = values.unset,
        friendly_name: Union[str, object] = values.unset,
    ) -> SipDomainInstance:
        """
        Update the SipDomainInstance

        :param voice_region:
        :param friendly_name:

        :returns: The updated SipDomainInstance
        """
        payload, _, _ = self._update(
            voice_region=voice_region, friendly_name=friendly_name
        )
        return SipDomainInstance(
            self._version, payload, sip_domain=self._solution["sip_domain"]
        )

    def update_with_http_info(
        self,
        voice_region: Union[str, object] = values.unset,
        friendly_name: Union[str, object] = values.unset,
    ) -> ApiResponse:
        """
        Update the SipDomainInstance and return response metadata

        :param voice_region:
        :param friendly_name:

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = self._update(
            voice_region=voice_region, friendly_name=friendly_name
        )
        instance = SipDomainInstance(
            self._version, payload, sip_domain=self._solution["sip_domain"]
        )
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

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

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

        data = values.of(
            {
                "VoiceRegion": voice_region,
                "FriendlyName": friendly_name,
            }
        )
        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,
        voice_region: Union[str, object] = values.unset,
        friendly_name: Union[str, object] = values.unset,
    ) -> SipDomainInstance:
        """
        Asynchronous coroutine to update the SipDomainInstance

        :param voice_region:
        :param friendly_name:

        :returns: The updated SipDomainInstance
        """
        payload, _, _ = await self._update_async(
            voice_region=voice_region, friendly_name=friendly_name
        )
        return SipDomainInstance(
            self._version, payload, sip_domain=self._solution["sip_domain"]
        )

    async def update_with_http_info_async(
        self,
        voice_region: Union[str, object] = values.unset,
        friendly_name: Union[str, object] = values.unset,
    ) -> ApiResponse:
        """
        Asynchronous coroutine to update the SipDomainInstance and return response metadata

        :param voice_region:
        :param friendly_name:

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = await self._update_async(
            voice_region=voice_region, friendly_name=friendly_name
        )
        instance = SipDomainInstance(
            self._version, payload, sip_domain=self._solution["sip_domain"]
        )
        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.Routes.V2.SipDomainContext {}>".format(context)


class SipDomainList(ListResource):

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

        :param version: Version that contains the resource

        """
        super().__init__(version)

    def get(self, sip_domain: str) -> SipDomainContext:
        """
        Constructs a SipDomainContext

        :param sip_domain:
        """
        return SipDomainContext(self._version, sip_domain=sip_domain)

    def __call__(self, sip_domain: str) -> SipDomainContext:
        """
        Constructs a SipDomainContext

        :param sip_domain:
        """
        return SipDomainContext(self._version, sip_domain=sip_domain)

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

        :returns: Machine friendly representation
        """
        return "<Twilio.Routes.V2.SipDomainList>"
