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

    Twilio - Accounts
    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, List, Optional, Union
from twilio.base import serialize, values
from twilio.base.api_response import ApiResponse

from twilio.base.instance_resource import InstanceResource
from twilio.base.list_resource import ListResource
from twilio.base.version import Version


class MessagingGeopermissionsInstance(InstanceResource):
    """
    :ivar permissions: A list of objects where each object represents the result of processing a messaging Geo Permission. Each object contains the following fields: `country_code`, the country code of the country for which the permission was updated; `type`, the type of the permission i.e. country; `enabled`, true if the permission is enabled else false; `error_code`, an integer where 0 indicates success and any non-zero value represents an error; and `error_messages`, an array of strings describing specific validation errors encountered. If the request is successful, the error_messages array will be empty.
    """

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

        self.permissions: Optional[Dict[str, object]] = payload.get("permissions")

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

        :returns: Machine friendly representation
        """

        return "<Twilio.Accounts.V1.MessagingGeopermissionsInstance>"


class MessagingGeopermissionsList(ListResource):

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

        :param version: Version that contains the resource

        """
        super().__init__(version)

        self._uri = "/Messaging/GeoPermissions"

    def _fetch(self, country_code: Union[str, object] = values.unset) -> tuple:
        """
        Internal helper for fetch operation

        Returns:
            tuple: (payload, status_code, headers)
        """
        headers = values.of({"Content-Type": "application/x-www-form-urlencoded"})

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

        params = values.of(
            {
                "CountryCode": country_code,
            }
        )

        return self._version.fetch_with_response_info(
            method="GET", uri=self._uri, headers=headers, params=params
        )

    def fetch(
        self, country_code: Union[str, object] = values.unset
    ) -> MessagingGeopermissionsInstance:
        """
        Fetch the MessagingGeopermissionsInstance

        :param country_code: The country code to filter the geo permissions. If provided, only the geo permission for the specified country will be returned.
        :returns: The fetched MessagingGeopermissionsInstance
        """
        payload, _, _ = self._fetch(country_code=country_code)
        return MessagingGeopermissionsInstance(self._version, payload)

    def fetch_with_http_info(
        self, country_code: Union[str, object] = values.unset
    ) -> ApiResponse:
        """
        Fetch the MessagingGeopermissionsInstance and return response metadata

        :param country_code: The country code to filter the geo permissions. If provided, only the geo permission for the specified country will be returned.
        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = self._fetch(country_code=country_code)
        instance = MessagingGeopermissionsInstance(self._version, payload)
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

    async def _fetch_async(
        self, country_code: Union[str, object] = values.unset
    ) -> tuple:
        """
        Internal async helper for fetch operation

        Returns:
            tuple: (payload, status_code, headers)
        """
        headers = values.of({"Content-Type": "application/x-www-form-urlencoded"})

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

        params = values.of(
            {
                "CountryCode": country_code,
            }
        )

        return await self._version.fetch_with_response_info_async(
            method="GET", uri=self._uri, headers=headers, params=params
        )

    async def fetch_async(
        self, country_code: Union[str, object] = values.unset
    ) -> MessagingGeopermissionsInstance:
        """
        Asynchronously fetch the MessagingGeopermissionsInstance

        :param country_code: The country code to filter the geo permissions. If provided, only the geo permission for the specified country will be returned.
        :returns: The fetched MessagingGeopermissionsInstance
        """
        payload, _, _ = await self._fetch_async(country_code=country_code)
        return MessagingGeopermissionsInstance(self._version, payload)

    async def fetch_with_http_info_async(
        self, country_code: Union[str, object] = values.unset
    ) -> ApiResponse:
        """
        Asynchronously fetch the MessagingGeopermissionsInstance and return response metadata

        :param country_code: The country code to filter the geo permissions. If provided, only the geo permission for the specified country will be returned.
        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = await self._fetch_async(
            country_code=country_code
        )
        instance = MessagingGeopermissionsInstance(self._version, payload)
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

    def _update(self, permissions: List[object]) -> tuple:
        """
        Internal helper for update operation

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

        data = values.of(
            {
                "Permissions": serialize.map(
                    permissions, lambda e: serialize.object(e)
                ),
            }
        )
        headers = values.of({"Content-Type": "application/x-www-form-urlencoded"})

        headers["Content-Type"] = "application/x-www-form-urlencoded"

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

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

    def update(self, permissions: List[object]) -> MessagingGeopermissionsInstance:
        """
        Update the MessagingGeopermissionsInstance

        :param permissions: A list of objects where each object represents the Geo Permission to be updated. Each object contains the following fields: `country_code`, unique code for each country of Geo Permission; `type`, permission type of the Geo Permission i.e. country; `enabled`, configure true for enabling the Geo Permission, false for disabling the Geo Permission.

        :returns: The updated MessagingGeopermissionsInstance
        """
        payload, _, _ = self._update(permissions=permissions)
        return MessagingGeopermissionsInstance(self._version, payload)

    def update_with_http_info(self, permissions: List[object]) -> ApiResponse:
        """
        Update the MessagingGeopermissionsInstance and return response metadata

        :param permissions: A list of objects where each object represents the Geo Permission to be updated. Each object contains the following fields: `country_code`, unique code for each country of Geo Permission; `type`, permission type of the Geo Permission i.e. country; `enabled`, configure true for enabling the Geo Permission, false for disabling the Geo Permission.

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = self._update(permissions=permissions)
        instance = MessagingGeopermissionsInstance(self._version, payload)
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

    async def _update_async(self, permissions: List[object]) -> tuple:
        """
        Internal async helper for update operation

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

        data = values.of(
            {
                "Permissions": serialize.map(
                    permissions, lambda e: serialize.object(e)
                ),
            }
        )
        headers = values.of({"Content-Type": "application/x-www-form-urlencoded"})

        headers["Content-Type"] = "application/x-www-form-urlencoded"

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

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

    async def update_async(
        self, permissions: List[object]
    ) -> MessagingGeopermissionsInstance:
        """
        Asynchronously update the MessagingGeopermissionsInstance

        :param permissions: A list of objects where each object represents the Geo Permission to be updated. Each object contains the following fields: `country_code`, unique code for each country of Geo Permission; `type`, permission type of the Geo Permission i.e. country; `enabled`, configure true for enabling the Geo Permission, false for disabling the Geo Permission.

        :returns: The updated MessagingGeopermissionsInstance
        """
        payload, _, _ = await self._update_async(permissions=permissions)
        return MessagingGeopermissionsInstance(self._version, payload)

    async def update_with_http_info_async(
        self, permissions: List[object]
    ) -> ApiResponse:
        """
        Asynchronously update the MessagingGeopermissionsInstance and return response metadata

        :param permissions: A list of objects where each object represents the Geo Permission to be updated. Each object contains the following fields: `country_code`, unique code for each country of Geo Permission; `type`, permission type of the Geo Permission i.e. country; `enabled`, configure true for enabling the Geo Permission, false for disabling the Geo Permission.

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = await self._update_async(
            permissions=permissions
        )
        instance = MessagingGeopermissionsInstance(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.Accounts.V1.MessagingGeopermissionsList>"
