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.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
    ) -> 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
        """
        headers = values.of({"Content-Type": "application/x-www-form-urlencoded"})

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

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

        payload = self._version.fetch(
            method="GET", uri=self._uri, headers=headers, params=params
        )

        return MessagingGeopermissionsInstance(self._version, payload)

    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
        """
        headers = values.of({"Content-Type": "application/x-www-form-urlencoded"})

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

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

        payload = await self._version.fetch_async(
            method="GET", uri=self._uri, headers=headers, params=params
        )

        return MessagingGeopermissionsInstance(self._version, payload)

    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 created MessagingGeopermissionsInstance
        """

        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"

        payload = self._version.update(
            method="PATCH", uri=self._uri, data=data, headers=headers
        )

        return MessagingGeopermissionsInstance(self._version, payload)

    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 created MessagingGeopermissionsInstance
        """

        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"

        payload = await self._version.update_async(
            method="PATCH", uri=self._uri, data=data, headers=headers
        )

        return MessagingGeopermissionsInstance(self._version, payload)

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

        :returns: Machine friendly representation
        """
        return "<Twilio.Accounts.V1.MessagingGeopermissionsList>"
