"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from .basesdk import BaseSDK
from enum import Enum
from postivo_client import errors, models, utils
from postivo_client._hooks import HookContext
from postivo_client.types import Nullable, OptionalNullable, UNSET
from postivo_client.utils import get_security_from_env
from postivo_client.utils.unmarshal_json_response import unmarshal_json_response
from typing import Any, List, Mapping, Optional


class GetAcceptEnum(str, Enum):
    APPLICATION_JSON = "application/json"
    APPLICATION_PROBLEM_PLUS_JSON = "application/problem+json"


class UpdateAcceptEnum(str, Enum):
    APPLICATION_JSON = "application/json"
    APPLICATION_PROBLEM_PLUS_JSON = "application/problem+json"


class ByExtID(BaseSDK):
    def get(
        self,
        *,
        ext_id: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        accept_header_override: Optional[GetAcceptEnum] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.GetContactByExternalIDResponse:
        r"""Retrieve contact details by EXT_ID

        Get the details of a contact from your Address Book using your external (custom) ID (the value you defined when creating the contact).

        :param ext_id: External (custom) ID of the contact to fetch.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param accept_header_override: Override the default accept header for this method
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.GetContactByExternalIDRequest(
            ext_id=ext_id,
        )

        req = self._build_request(
            method="GET",
            path="/contacts/external/{ext_id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value=accept_header_override.value
            if accept_header_override is not None
            else "application/json;q=1, application/problem+json;q=0",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["5XX"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getContactByExternalId",
                oauth2_scopes=None,
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "404", "4XX", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.ContactResponse, http_res)
        if utils.match_response(
            http_res, ["400", "401", "404", "4XX"], "application/problem+json"
        ):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "5XX", "application/problem+json"):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "default", "application/problem+json"):
            return unmarshal_json_response(models.ErrorResponse, http_res)

        raise errors.SDKDefaultError("Unexpected response received", http_res)

    async def get_async(
        self,
        *,
        ext_id: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        accept_header_override: Optional[GetAcceptEnum] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.GetContactByExternalIDResponse:
        r"""Retrieve contact details by EXT_ID

        Get the details of a contact from your Address Book using your external (custom) ID (the value you defined when creating the contact).

        :param ext_id: External (custom) ID of the contact to fetch.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param accept_header_override: Override the default accept header for this method
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.GetContactByExternalIDRequest(
            ext_id=ext_id,
        )

        req = self._build_request_async(
            method="GET",
            path="/contacts/external/{ext_id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value=accept_header_override.value
            if accept_header_override is not None
            else "application/json;q=1, application/problem+json;q=0",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["5XX"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getContactByExternalId",
                oauth2_scopes=None,
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "404", "4XX", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.ContactResponse, http_res)
        if utils.match_response(
            http_res, ["400", "401", "404", "4XX"], "application/problem+json"
        ):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "5XX", "application/problem+json"):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "default", "application/problem+json"):
            return unmarshal_json_response(models.ErrorResponse, http_res)

        raise errors.SDKDefaultError("Unexpected response received", http_res)

    def update(
        self,
        *,
        ext_id_param: str,
        name: Nullable[str],
        address: Nullable[str],
        post_code: Nullable[str],
        city: Nullable[str],
        name2: OptionalNullable[str] = UNSET,
        home_number: OptionalNullable[str] = UNSET,
        flat_number: OptionalNullable[str] = UNSET,
        country: OptionalNullable[str] = "PL",
        phone_number: OptionalNullable[str] = UNSET,
        ext_id: OptionalNullable[str] = UNSET,
        group_ids: OptionalNullable[List[int]] = UNSET,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        accept_header_override: Optional[UpdateAcceptEnum] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.UpdateContactByExternalIDResponse:
        r"""Update a contact by EXT_ID

        Update a contact by its external (custom) ID - the value you defined when creating the contact.

        :param ext_id_param: External (custom) ID of the contact to update.
        :param name: Name (person or company) — line 1.
        :param address: Street address.
        :param post_code: Postal code. For `PL`, 5-digit values are normalized to the `NN-NNN` format.
        :param city: City.
        :param name2: Name (person or company) — line 2.
        :param home_number: Building number.
        :param flat_number: Apartment (unit) number.
        :param country: Country code in ISO 3166-1 alpha-2 format. Default: \"PL\". Value is automatically uppercased. Full list: https://www.iso.org/iso-3166-country-codes.html
        :param phone_number: Phone number (E.164 format recommended).
        :param ext_id: Custom (external) contact ID; must be unique per contact.
        :param group_ids: IDs of groups the contact belongs to.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param accept_header_override: Override the default accept header for this method
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.UpdateContactByExternalIDRequest(
            ext_id_param=ext_id_param,
            contact=models.Contact(
                name=name,
                name2=name2,
                address=address,
                home_number=home_number,
                flat_number=flat_number,
                post_code=post_code,
                city=city,
                country=country,
                phone_number=phone_number,
                ext_id=ext_id,
                group_ids=group_ids,
            ),
        )

        req = self._build_request(
            method="PUT",
            path="/contacts/external/{ext_id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value=accept_header_override.value
            if accept_header_override is not None
            else "application/json;q=1, application/problem+json;q=0",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.contact, False, False, "json", models.Contact
            ),
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["5XX"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="updateContactByExternalId",
                oauth2_scopes=None,
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "403", "404", "4XX", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return models.UpdateContactByExternalIDResponse(
                result=unmarshal_json_response(models.ContactResponse, http_res),
                headers=utils.get_response_headers(http_res.headers),
            )
        if utils.match_response(
            http_res, ["400", "401", "403", "404", "4XX"], "application/problem+json"
        ):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "5XX", "application/problem+json"):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "default", "application/problem+json"):
            return models.UpdateContactByExternalIDResponse(
                result=unmarshal_json_response(models.ErrorResponse, http_res),
                headers={},
            )

        raise errors.SDKDefaultError("Unexpected response received", http_res)

    async def update_async(
        self,
        *,
        ext_id_param: str,
        name: Nullable[str],
        address: Nullable[str],
        post_code: Nullable[str],
        city: Nullable[str],
        name2: OptionalNullable[str] = UNSET,
        home_number: OptionalNullable[str] = UNSET,
        flat_number: OptionalNullable[str] = UNSET,
        country: OptionalNullable[str] = "PL",
        phone_number: OptionalNullable[str] = UNSET,
        ext_id: OptionalNullable[str] = UNSET,
        group_ids: OptionalNullable[List[int]] = UNSET,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        accept_header_override: Optional[UpdateAcceptEnum] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.UpdateContactByExternalIDResponse:
        r"""Update a contact by EXT_ID

        Update a contact by its external (custom) ID - the value you defined when creating the contact.

        :param ext_id_param: External (custom) ID of the contact to update.
        :param name: Name (person or company) — line 1.
        :param address: Street address.
        :param post_code: Postal code. For `PL`, 5-digit values are normalized to the `NN-NNN` format.
        :param city: City.
        :param name2: Name (person or company) — line 2.
        :param home_number: Building number.
        :param flat_number: Apartment (unit) number.
        :param country: Country code in ISO 3166-1 alpha-2 format. Default: \"PL\". Value is automatically uppercased. Full list: https://www.iso.org/iso-3166-country-codes.html
        :param phone_number: Phone number (E.164 format recommended).
        :param ext_id: Custom (external) contact ID; must be unique per contact.
        :param group_ids: IDs of groups the contact belongs to.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param accept_header_override: Override the default accept header for this method
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.UpdateContactByExternalIDRequest(
            ext_id_param=ext_id_param,
            contact=models.Contact(
                name=name,
                name2=name2,
                address=address,
                home_number=home_number,
                flat_number=flat_number,
                post_code=post_code,
                city=city,
                country=country,
                phone_number=phone_number,
                ext_id=ext_id,
                group_ids=group_ids,
            ),
        )

        req = self._build_request_async(
            method="PUT",
            path="/contacts/external/{ext_id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value=accept_header_override.value
            if accept_header_override is not None
            else "application/json;q=1, application/problem+json;q=0",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.contact, False, False, "json", models.Contact
            ),
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["5XX"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="updateContactByExternalId",
                oauth2_scopes=None,
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "403", "404", "4XX", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return models.UpdateContactByExternalIDResponse(
                result=unmarshal_json_response(models.ContactResponse, http_res),
                headers=utils.get_response_headers(http_res.headers),
            )
        if utils.match_response(
            http_res, ["400", "401", "403", "404", "4XX"], "application/problem+json"
        ):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "5XX", "application/problem+json"):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "default", "application/problem+json"):
            return models.UpdateContactByExternalIDResponse(
                result=unmarshal_json_response(models.ErrorResponse, http_res),
                headers={},
            )

        raise errors.SDKDefaultError("Unexpected response received", http_res)

    def delete(
        self,
        *,
        ext_id: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> Optional[models.DeleteContactByExternalIDResponse]:
        r"""Delete a contact by EXT_ID

        Remove a contact from your account by its external (custom) ID - the value defined when the contact was created.

        :param ext_id: External (custom) ID of the contact to remove.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.DeleteContactByExternalIDRequest(
            ext_id=ext_id,
        )

        req = self._build_request(
            method="DELETE",
            path="/contacts/external/{ext_id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/problem+json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["5XX"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="deleteContactByExternalId",
                oauth2_scopes=None,
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "403", "404", "4XX", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "204", "*"):
            return models.DeleteContactByExternalIDResponse(
                result="", headers=utils.get_response_headers(http_res.headers)
            )
        if utils.match_response(
            http_res, ["400", "401", "403", "404", "4XX"], "application/problem+json"
        ):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "5XX", "application/problem+json"):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "default", "application/problem+json"):
            return models.DeleteContactByExternalIDResponse(
                result=unmarshal_json_response(models.ErrorResponse, http_res),
                headers={},
            )

        raise errors.SDKDefaultError("Unexpected response received", http_res)

    async def delete_async(
        self,
        *,
        ext_id: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> Optional[models.DeleteContactByExternalIDResponse]:
        r"""Delete a contact by EXT_ID

        Remove a contact from your account by its external (custom) ID - the value defined when the contact was created.

        :param ext_id: External (custom) ID of the contact to remove.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.DeleteContactByExternalIDRequest(
            ext_id=ext_id,
        )

        req = self._build_request_async(
            method="DELETE",
            path="/contacts/external/{ext_id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/problem+json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["5XX"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="deleteContactByExternalId",
                oauth2_scopes=None,
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "403", "404", "4XX", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "204", "*"):
            return models.DeleteContactByExternalIDResponse(
                result="", headers=utils.get_response_headers(http_res.headers)
            )
        if utils.match_response(
            http_res, ["400", "401", "403", "404", "4XX"], "application/problem+json"
        ):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "5XX", "application/problem+json"):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "default", "application/problem+json"):
            return models.DeleteContactByExternalIDResponse(
                result=unmarshal_json_response(models.ErrorResponse, http_res),
                headers={},
            )

        raise errors.SDKDefaultError("Unexpected response received", http_res)

    def remove_from_group(
        self,
        *,
        ext_id: str,
        group_id: int,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> Optional[models.RemoveContactByExtIDToGroupResponse]:
        r"""Remove a contact from a group by EXT_ID

        Remove a contact from a group in your Address Book using the contact’s external (custom) ID. This operation does not delete the contact; it only detaches the contact from the group. Provide the contact’s `ext_id` and the group’s `group_id` parameters to perform the detachment.

        :param ext_id: External (custom) ID of the contact to detach from the group.
        :param group_id: Group `id` to detach from the contact.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.RemoveContactByExtIDToGroupRequest(
            ext_id=ext_id,
            group_id=group_id,
        )

        req = self._build_request(
            method="DELETE",
            path="/contacts/external/{ext_id}/group/{group_id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/problem+json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["5XX"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="removeContactByExtIdToGroup",
                oauth2_scopes=None,
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "403", "404", "4XX", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "204", "*"):
            return models.RemoveContactByExtIDToGroupResponse(
                result="", headers=utils.get_response_headers(http_res.headers)
            )
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(
            http_res, ["400", "401", "403", "4XX"], "application/problem+json"
        ):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "5XX", "application/problem+json"):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "default", "application/problem+json"):
            return models.RemoveContactByExtIDToGroupResponse(
                result=unmarshal_json_response(models.ErrorResponse, http_res),
                headers={},
            )

        raise errors.SDKDefaultError("Unexpected response received", http_res)

    async def remove_from_group_async(
        self,
        *,
        ext_id: str,
        group_id: int,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> Optional[models.RemoveContactByExtIDToGroupResponse]:
        r"""Remove a contact from a group by EXT_ID

        Remove a contact from a group in your Address Book using the contact’s external (custom) ID. This operation does not delete the contact; it only detaches the contact from the group. Provide the contact’s `ext_id` and the group’s `group_id` parameters to perform the detachment.

        :param ext_id: External (custom) ID of the contact to detach from the group.
        :param group_id: Group `id` to detach from the contact.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.RemoveContactByExtIDToGroupRequest(
            ext_id=ext_id,
            group_id=group_id,
        )

        req = self._build_request_async(
            method="DELETE",
            path="/contacts/external/{ext_id}/group/{group_id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/problem+json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["5XX"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="removeContactByExtIdToGroup",
                oauth2_scopes=None,
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "403", "404", "4XX", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "204", "*"):
            return models.RemoveContactByExtIDToGroupResponse(
                result="", headers=utils.get_response_headers(http_res.headers)
            )
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(
            http_res, ["400", "401", "403", "4XX"], "application/problem+json"
        ):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "5XX", "application/problem+json"):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "default", "application/problem+json"):
            return models.RemoveContactByExtIDToGroupResponse(
                result=unmarshal_json_response(models.ErrorResponse, http_res),
                headers={},
            )

        raise errors.SDKDefaultError("Unexpected response received", http_res)

    def add_to_group(
        self,
        *,
        ext_id: str,
        group_id: int,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> Optional[models.AddContactByExtIDToGroupResponse]:
        r"""Add a contact to a group by EXT_ID

        Assign a contact to a group using the contact’s external (custom) ID (assigned when creating the contact). If a contact and a group exist in your account, you can add the contact to that group.

        Provide the contact’s `ext_id` and the group’s `group_id` parameters to perform the assignment.

        :param ext_id: External (custom) ID of the contact to add to the group.
        :param group_id: Group `id` to associate with the contact.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.AddContactByExtIDToGroupRequest(
            ext_id=ext_id,
            group_id=group_id,
        )

        req = self._build_request(
            method="PATCH",
            path="/contacts/external/{ext_id}/group/{group_id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/problem+json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["5XX"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="addContactByExtIdToGroup",
                oauth2_scopes=None,
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "403", "404", "4XX", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "204", "*"):
            return models.AddContactByExtIDToGroupResponse(
                result="", headers=utils.get_response_headers(http_res.headers)
            )
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(
            http_res, ["400", "401", "403", "4XX"], "application/problem+json"
        ):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "5XX", "application/problem+json"):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "default", "application/problem+json"):
            return models.AddContactByExtIDToGroupResponse(
                result=unmarshal_json_response(models.ErrorResponse, http_res),
                headers={},
            )

        raise errors.SDKDefaultError("Unexpected response received", http_res)

    async def add_to_group_async(
        self,
        *,
        ext_id: str,
        group_id: int,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> Optional[models.AddContactByExtIDToGroupResponse]:
        r"""Add a contact to a group by EXT_ID

        Assign a contact to a group using the contact’s external (custom) ID (assigned when creating the contact). If a contact and a group exist in your account, you can add the contact to that group.

        Provide the contact’s `ext_id` and the group’s `group_id` parameters to perform the assignment.

        :param ext_id: External (custom) ID of the contact to add to the group.
        :param group_id: Group `id` to associate with the contact.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.AddContactByExtIDToGroupRequest(
            ext_id=ext_id,
            group_id=group_id,
        )

        req = self._build_request_async(
            method="PATCH",
            path="/contacts/external/{ext_id}/group/{group_id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/problem+json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["5XX"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="addContactByExtIdToGroup",
                oauth2_scopes=None,
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "403", "404", "4XX", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "204", "*"):
            return models.AddContactByExtIDToGroupResponse(
                result="", headers=utils.get_response_headers(http_res.headers)
            )
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(
            http_res, ["400", "401", "403", "4XX"], "application/problem+json"
        ):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "5XX", "application/problem+json"):
            response_data = unmarshal_json_response(errors.ErrorResponseData, http_res)
            raise errors.ErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "default", "application/problem+json"):
            return models.AddContactByExtIDToGroupResponse(
                result=unmarshal_json_response(models.ErrorResponse, http_res),
                headers={},
            )

        raise errors.SDKDefaultError("Unexpected response received", http_res)
