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

    Twilio - Lookups
    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 LookupOverrideInstance(InstanceResource):

    class OverridesRequest(object):
        """
        :ivar line_type: The new line type to override the original line type
        :ivar reason: The reason for the override
        """

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

            self.line_type: Optional["LookupOverrideInstance.str"] = payload.get(
                "line_type"
            )
            self.reason: Optional[str] = payload.get("reason")

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

    """
    :ivar phone_number: The phone number for which the override was created
    :ivar original_line_type: The original line type
    :ivar overridden_line_type: The new line type after the override
    :ivar override_reason: The reason for the override
    :ivar override_timestamp: 
    :ivar overridden_by_account_sid: The Account SID for the user who made the override
    :ivar code: Twilio-specific error code
    :ivar message: Error message
    :ivar more_info: Link to Error Code References
    :ivar status: HTTP response status code
    :ivar field: Limit of requests for the bucket
    :ivar limit: Limit of requests for the bucket
    :ivar bucket: Name of the bucket
    :ivar owner: Owner of the rule
    :ivar ttl: Time to live of the rule
    """

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

        self.phone_number: Optional[str] = payload.get("phone_number")
        self.original_line_type: Optional[str] = payload.get("original_line_type")
        self.overridden_line_type: Optional[str] = payload.get("overridden_line_type")
        self.override_reason: Optional[str] = payload.get("override_reason")
        self.override_timestamp: Optional[datetime] = deserialize.iso8601_datetime(
            payload.get("override_timestamp")
        )
        self.overridden_by_account_sid: Optional[str] = payload.get(
            "overridden_by_account_sid"
        )
        self.code: Optional[int] = payload.get("code")
        self.message: Optional[str] = payload.get("message")
        self.more_info: Optional[str] = payload.get("more_info")
        self.status: Optional[int] = payload.get("status")
        self.field: Optional[str] = payload.get("field")
        self.limit: Optional[int] = payload.get("limit")
        self.bucket: Optional[str] = payload.get("bucket")
        self.owner: Optional[str] = payload.get("owner")
        self.ttl: Optional[int] = payload.get("ttl")

        self._solution = {
            "field": field or self.field,
            "phone_number": phone_number or self.phone_number,
        }
        self._context: Optional[LookupOverrideContext] = None

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

        :returns: LookupOverrideContext for this LookupOverrideInstance
        """
        if self._context is None:
            self._context = LookupOverrideContext(
                self._version,
                field=self._solution["field"],
                phone_number=self._solution["phone_number"],
            )
        return self._context

    def create(
        self, overrides_request: Union[OverridesRequest, object] = values.unset
    ) -> "LookupOverrideInstance":
        """
        Create the LookupOverrideInstance

        :param overrides_request:

        :returns: The created LookupOverrideInstance
        """
        return self._proxy.create(
            overrides_request=overrides_request,
        )

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

        :param overrides_request:

        :returns: The created LookupOverrideInstance
        """
        return await self._proxy.create_async(
            overrides_request=overrides_request,
        )

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

        :param overrides_request:

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

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

        :param overrides_request:

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

    def delete(self) -> bool:
        """
        Deletes the LookupOverrideInstance


        :returns: True if delete succeeds, False otherwise
        """
        return self._proxy.delete()

    async def delete_async(self) -> bool:
        """
        Asynchronous coroutine that deletes the LookupOverrideInstance


        :returns: True if delete succeeds, False otherwise
        """
        return await self._proxy.delete_async()

    def delete_with_http_info(self) -> ApiResponse:
        """
        Deletes the LookupOverrideInstance with HTTP info


        :returns: ApiResponse with success boolean, status code, and headers
        """
        return self._proxy.delete_with_http_info()

    async def delete_with_http_info_async(self) -> ApiResponse:
        """
        Asynchronous coroutine that deletes the LookupOverrideInstance with HTTP info


        :returns: ApiResponse with success boolean, status code, and headers
        """
        return await self._proxy.delete_with_http_info_async()

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


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

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


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

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


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

    def update(
        self, overrides_request: Union[OverridesRequest, object] = values.unset
    ) -> "LookupOverrideInstance":
        """
        Update the LookupOverrideInstance

        :param overrides_request:

        :returns: The updated LookupOverrideInstance
        """
        return self._proxy.update(
            overrides_request=overrides_request,
        )

    async def update_async(
        self, overrides_request: Union[OverridesRequest, object] = values.unset
    ) -> "LookupOverrideInstance":
        """
        Asynchronous coroutine to update the LookupOverrideInstance

        :param overrides_request:

        :returns: The updated LookupOverrideInstance
        """
        return await self._proxy.update_async(
            overrides_request=overrides_request,
        )

    def update_with_http_info(
        self, overrides_request: Union[OverridesRequest, object] = values.unset
    ) -> ApiResponse:
        """
        Update the LookupOverrideInstance with HTTP info

        :param overrides_request:

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

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

        :param overrides_request:

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

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


class LookupOverrideContext(InstanceContext):

    class OverridesRequest(object):
        """
        :ivar line_type: The new line type to override the original line type
        :ivar reason: The reason for the override
        """

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

            self.line_type: Optional["LookupOverrideInstance.str"] = payload.get(
                "line_type"
            )
            self.reason: Optional[str] = payload.get("reason")

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

    def __init__(self, version: Version, field: str, phone_number: str):
        """
        Initialize the LookupOverrideContext

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

        # Path Solution
        self._solution = {
            "field": field,
            "phone_number": phone_number,
        }
        self._uri = "/PhoneNumbers/{phone_number}/Overrides/{field}".format(
            **self._solution
        )

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

        Returns:
            tuple: (payload, status_code, headers)
        """
        data = overrides_request.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, overrides_request: Union[OverridesRequest, object] = values.unset
    ) -> LookupOverrideInstance:
        """
        Create the LookupOverrideInstance

        :param overrides_request:

        :returns: The created LookupOverrideInstance
        """
        payload, _, _ = self._create(overrides_request=overrides_request)
        return LookupOverrideInstance(
            self._version,
            payload,
            field=self._solution["field"],
            phone_number=self._solution["phone_number"],
        )

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

        :param overrides_request:

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = self._create(
            overrides_request=overrides_request
        )
        instance = LookupOverrideInstance(
            self._version,
            payload,
            field=self._solution["field"],
            phone_number=self._solution["phone_number"],
        )
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

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

        Returns:
            tuple: (payload, status_code, headers)
        """
        data = overrides_request.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, overrides_request: Union[OverridesRequest, object] = values.unset
    ) -> LookupOverrideInstance:
        """
        Asynchronous coroutine to create the LookupOverrideInstance

        :param overrides_request:

        :returns: The created LookupOverrideInstance
        """
        payload, _, _ = await self._create_async(overrides_request=overrides_request)
        return LookupOverrideInstance(
            self._version,
            payload,
            field=self._solution["field"],
            phone_number=self._solution["phone_number"],
        )

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

        :param overrides_request:

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = await self._create_async(
            overrides_request=overrides_request
        )
        instance = LookupOverrideInstance(
            self._version,
            payload,
            field=self._solution["field"],
            phone_number=self._solution["phone_number"],
        )
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

    def _delete(self) -> tuple:
        """
        Internal helper for delete operation

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

        headers = values.of({})

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

        return self._version.delete_with_response_info(
            method="DELETE", uri=self._uri, headers=headers
        )

    def delete(self) -> bool:
        """
        Deletes the LookupOverrideInstance


        :returns: True if delete succeeds, False otherwise
        """
        success, _, _ = self._delete()
        return success

    def delete_with_http_info(self) -> ApiResponse:
        """
        Deletes the LookupOverrideInstance and return response metadata


        :returns: ApiResponse with success boolean, status code, and headers
        """
        success, status_code, headers = self._delete()
        return ApiResponse(data=success, status_code=status_code, headers=headers)

    async def _delete_async(self) -> tuple:
        """
        Internal async helper for delete operation

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

        headers = values.of({})

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

        return await self._version.delete_with_response_info_async(
            method="DELETE", uri=self._uri, headers=headers
        )

    async def delete_async(self) -> bool:
        """
        Asynchronous coroutine that deletes the LookupOverrideInstance


        :returns: True if delete succeeds, False otherwise
        """
        success, _, _ = await self._delete_async()
        return success

    async def delete_with_http_info_async(self) -> ApiResponse:
        """
        Asynchronous coroutine that deletes the LookupOverrideInstance and return response metadata


        :returns: ApiResponse with success boolean, status code, and headers
        """
        success, status_code, headers = await self._delete_async()
        return ApiResponse(data=success, status_code=status_code, headers=headers)

    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) -> LookupOverrideInstance:
        """
        Fetch the LookupOverrideInstance


        :returns: The fetched LookupOverrideInstance
        """
        payload, _, _ = self._fetch()
        return LookupOverrideInstance(
            self._version,
            payload,
            field=self._solution["field"],
            phone_number=self._solution["phone_number"],
        )

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


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


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

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


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

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

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

        headers = values.of({})

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

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

        return self._version.update_with_response_info(
            method="PUT", uri=self._uri, data=data, headers=headers
        )

    def update(
        self, overrides_request: Union[OverridesRequest, object] = values.unset
    ) -> LookupOverrideInstance:
        """
        Update the LookupOverrideInstance

        :param overrides_request:

        :returns: The updated LookupOverrideInstance
        """
        payload, _, _ = self._update(overrides_request=overrides_request)
        return LookupOverrideInstance(
            self._version,
            payload,
            field=self._solution["field"],
            phone_number=self._solution["phone_number"],
        )

    def update_with_http_info(
        self, overrides_request: Union[OverridesRequest, object] = values.unset
    ) -> ApiResponse:
        """
        Update the LookupOverrideInstance and return response metadata

        :param overrides_request:

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = self._update(
            overrides_request=overrides_request
        )
        instance = LookupOverrideInstance(
            self._version,
            payload,
            field=self._solution["field"],
            phone_number=self._solution["phone_number"],
        )
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

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

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

        headers = values.of({})

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

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

        return await self._version.update_with_response_info_async(
            method="PUT", uri=self._uri, data=data, headers=headers
        )

    async def update_async(
        self, overrides_request: Union[OverridesRequest, object] = values.unset
    ) -> LookupOverrideInstance:
        """
        Asynchronous coroutine to update the LookupOverrideInstance

        :param overrides_request:

        :returns: The updated LookupOverrideInstance
        """
        payload, _, _ = await self._update_async(overrides_request=overrides_request)
        return LookupOverrideInstance(
            self._version,
            payload,
            field=self._solution["field"],
            phone_number=self._solution["phone_number"],
        )

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

        :param overrides_request:

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = await self._update_async(
            overrides_request=overrides_request
        )
        instance = LookupOverrideInstance(
            self._version,
            payload,
            field=self._solution["field"],
            phone_number=self._solution["phone_number"],
        )
        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.Lookups.V2.LookupOverrideContext {}>".format(context)


class LookupOverrideList(ListResource):

    class OverridesRequest(object):
        """
        :ivar line_type: The new line type to override the original line type
        :ivar reason: The reason for the override
        """

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

            self.line_type: Optional["LookupOverrideInstance.str"] = payload.get(
                "line_type"
            )
            self.reason: Optional[str] = payload.get("reason")

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

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

        :param version: Version that contains the resource

        """
        super().__init__(version)

    def get(self, field: str, phone_number: str) -> LookupOverrideContext:
        """
        Constructs a LookupOverrideContext

        :param field:
        :param phone_number:
        """
        return LookupOverrideContext(
            self._version, field=field, phone_number=phone_number
        )

    def __call__(self, field: str, phone_number: str) -> LookupOverrideContext:
        """
        Constructs a LookupOverrideContext

        :param field:
        :param phone_number:
        """
        return LookupOverrideContext(
            self._version, field=field, phone_number=phone_number
        )

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

        :returns: Machine friendly representation
        """
        return "<Twilio.Lookups.V2.LookupOverrideList>"
