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

from .basesdk import BaseSDK
from flexprice import models, utils
from flexprice._hooks import HookContext
from flexprice.types import OptionalNullable, UNSET
from flexprice.utils.unmarshal_json_response import unmarshal_json_response
from typing import Any, Dict, List, Mapping, Optional, Union


class Customers(BaseSDK):
    def update_customer(
        self,
        *,
        id: Optional[str] = None,
        external_customer_id: Optional[str] = None,
        address_city: Optional[str] = None,
        address_country: Optional[str] = None,
        address_line1: Optional[str] = None,
        address_line2: Optional[str] = None,
        address_postal_code: Optional[str] = None,
        address_state: Optional[str] = None,
        email: Optional[str] = None,
        external_id: Optional[str] = None,
        integration_entity_mapping: Optional[
            Union[
                List[models.DtoIntegrationEntityMapping],
                List[models.DtoIntegrationEntityMappingTypedDict],
            ]
        ] = None,
        metadata: Optional[Dict[str, str]] = None,
        name: Optional[str] = None,
        parent_customer_external_id: Optional[str] = None,
        parent_customer_id: Optional[str] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.DtoCustomerResponse:
        r"""Update customer

        Use when updating customer details (e.g. name, email, or metadata). Identify by id or external_customer_id.

        :param id: Customer ID
        :param external_customer_id: Customer External ID
        :param address_city: address_city is the updated city name with maximum 100 characters
        :param address_country: address_country is the updated two-letter ISO 3166-1 alpha-2 country code
        :param address_line1: address_line1 is the updated primary address line with maximum 255 characters
        :param address_line2: address_line2 is the updated secondary address line with maximum 255 characters
        :param address_postal_code: address_postal_code is the updated postal code with maximum 20 characters
        :param address_state: address_state is the updated state, province, or region name with maximum 100 characters
        :param email: email is the updated email address and must be a valid email format if provided
        :param external_id: external_id is the updated external identifier for the customer
        :param integration_entity_mapping: integration_entity_mapping contains provider integration mappings for this customer
        :param metadata: metadata contains updated key-value pairs that will replace existing metadata
        :param name: name is the updated name or company name for the customer
        :param parent_customer_external_id: parent_customer_external_id is the external ID of the parent customer from your system
            Exactly one of parent_customer_id or parent_customer_external_id may be provided
            If you provide the external ID, the parent customer value will be ignored
        :param parent_customer_id: parent_customer_id is the internal FlexPrice ID of the parent customer
        :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.UpdateCustomerRequest(
            id=id,
            external_customer_id=external_customer_id,
            body=models.DtoUpdateCustomerRequest(
                address_city=address_city,
                address_country=address_country,
                address_line1=address_line1,
                address_line2=address_line2,
                address_postal_code=address_postal_code,
                address_state=address_state,
                email=email,
                external_id=external_id,
                integration_entity_mapping=utils.get_pydantic_model(
                    integration_entity_mapping,
                    Optional[List[models.DtoIntegrationEntityMapping]],
                ),
                metadata=metadata,
                name=name,
                parent_customer_external_id=parent_customer_external_id,
                parent_customer_id=parent_customer_id,
            ),
        )

        req = self._build_request(
            method="PUT",
            path="/customers",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.body, False, False, "json", models.DtoUpdateCustomerRequest
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="updateCustomer",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.DtoCustomerResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise models.errors.FlexpriceDefaultError(
            "Unexpected response received", http_res
        )

    async def update_customer_async(
        self,
        *,
        id: Optional[str] = None,
        external_customer_id: Optional[str] = None,
        address_city: Optional[str] = None,
        address_country: Optional[str] = None,
        address_line1: Optional[str] = None,
        address_line2: Optional[str] = None,
        address_postal_code: Optional[str] = None,
        address_state: Optional[str] = None,
        email: Optional[str] = None,
        external_id: Optional[str] = None,
        integration_entity_mapping: Optional[
            Union[
                List[models.DtoIntegrationEntityMapping],
                List[models.DtoIntegrationEntityMappingTypedDict],
            ]
        ] = None,
        metadata: Optional[Dict[str, str]] = None,
        name: Optional[str] = None,
        parent_customer_external_id: Optional[str] = None,
        parent_customer_id: Optional[str] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.DtoCustomerResponse:
        r"""Update customer

        Use when updating customer details (e.g. name, email, or metadata). Identify by id or external_customer_id.

        :param id: Customer ID
        :param external_customer_id: Customer External ID
        :param address_city: address_city is the updated city name with maximum 100 characters
        :param address_country: address_country is the updated two-letter ISO 3166-1 alpha-2 country code
        :param address_line1: address_line1 is the updated primary address line with maximum 255 characters
        :param address_line2: address_line2 is the updated secondary address line with maximum 255 characters
        :param address_postal_code: address_postal_code is the updated postal code with maximum 20 characters
        :param address_state: address_state is the updated state, province, or region name with maximum 100 characters
        :param email: email is the updated email address and must be a valid email format if provided
        :param external_id: external_id is the updated external identifier for the customer
        :param integration_entity_mapping: integration_entity_mapping contains provider integration mappings for this customer
        :param metadata: metadata contains updated key-value pairs that will replace existing metadata
        :param name: name is the updated name or company name for the customer
        :param parent_customer_external_id: parent_customer_external_id is the external ID of the parent customer from your system
            Exactly one of parent_customer_id or parent_customer_external_id may be provided
            If you provide the external ID, the parent customer value will be ignored
        :param parent_customer_id: parent_customer_id is the internal FlexPrice ID of the parent customer
        :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.UpdateCustomerRequest(
            id=id,
            external_customer_id=external_customer_id,
            body=models.DtoUpdateCustomerRequest(
                address_city=address_city,
                address_country=address_country,
                address_line1=address_line1,
                address_line2=address_line2,
                address_postal_code=address_postal_code,
                address_state=address_state,
                email=email,
                external_id=external_id,
                integration_entity_mapping=utils.get_pydantic_model(
                    integration_entity_mapping,
                    Optional[List[models.DtoIntegrationEntityMapping]],
                ),
                metadata=metadata,
                name=name,
                parent_customer_external_id=parent_customer_external_id,
                parent_customer_id=parent_customer_id,
            ),
        )

        req = self._build_request_async(
            method="PUT",
            path="/customers",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.body, False, False, "json", models.DtoUpdateCustomerRequest
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="updateCustomer",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.DtoCustomerResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise models.errors.FlexpriceDefaultError(
            "Unexpected response received", http_res
        )

    def create_customer(
        self,
        *,
        external_id: str,
        address_city: Optional[str] = None,
        address_country: Optional[str] = None,
        address_line1: Optional[str] = None,
        address_line2: Optional[str] = None,
        address_postal_code: Optional[str] = None,
        address_state: Optional[str] = None,
        email: Optional[str] = None,
        integration_entity_mapping: Optional[
            Union[
                List[models.DtoIntegrationEntityMapping],
                List[models.DtoIntegrationEntityMappingTypedDict],
            ]
        ] = None,
        metadata: Optional[Dict[str, str]] = None,
        name: Optional[str] = None,
        parent_customer_external_id: Optional[str] = None,
        parent_customer_id: Optional[str] = None,
        skip_onboarding_workflow: Optional[bool] = None,
        tax_rate_overrides: Optional[
            Union[
                List[models.DtoTaxRateOverride],
                List[models.DtoTaxRateOverrideTypedDict],
            ]
        ] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.DtoCustomerResponse:
        r"""Create customer

        Use when onboarding a new billing customer (e.g. sign-up or CRM sync). Ideal for linking via external_customer_id to your app's user id.

        :param external_id: external_id is the unique identifier from your system to reference this customer (required)
        :param address_city: address_city is the city name with maximum 100 characters
        :param address_country: address_country is the two-letter ISO 3166-1 alpha-2 country code
        :param address_line1: address_line1 is the primary address line with maximum 255 characters
        :param address_line2: address_line2 is the secondary address line with maximum 255 characters
        :param address_postal_code: address_postal_code is the ZIP code or postal code with maximum 20 characters
        :param address_state: address_state is the state, province, or region name with maximum 100 characters
        :param email: email is the customer's email address and must be a valid email format if provided
        :param integration_entity_mapping: integration_entity_mapping contains provider integration mappings for this customer
        :param metadata: metadata contains additional key-value pairs for storing extra information
        :param name: name is the full name or company name of the customer
        :param parent_customer_external_id: parent_customer_external_id is the external ID of the parent customer from your system
            Exactly one of parent_customer_id or parent_customer_external_id may be provided
        :param parent_customer_id: parent_customer_id is the internal FlexPrice ID of the parent customer
        :param skip_onboarding_workflow: skip_onboarding_workflow when true, prevents the customer onboarding workflow from being triggered
            This is used internally when a customer is created via a workflow to prevent infinite loops
            Default: false
        :param tax_rate_overrides: tax_rate_overrides contains tax rate configurations to be linked to this customer
        :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.DtoCreateCustomerRequest(
            address_city=address_city,
            address_country=address_country,
            address_line1=address_line1,
            address_line2=address_line2,
            address_postal_code=address_postal_code,
            address_state=address_state,
            email=email,
            external_id=external_id,
            integration_entity_mapping=utils.get_pydantic_model(
                integration_entity_mapping,
                Optional[List[models.DtoIntegrationEntityMapping]],
            ),
            metadata=metadata,
            name=name,
            parent_customer_external_id=parent_customer_external_id,
            parent_customer_id=parent_customer_id,
            skip_onboarding_workflow=skip_onboarding_workflow,
            tax_rate_overrides=utils.get_pydantic_model(
                tax_rate_overrides, Optional[List[models.DtoTaxRateOverride]]
            ),
        )

        req = self._build_request(
            method="POST",
            path="/customers",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request, False, False, "json", models.DtoCreateCustomerRequest
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="createCustomer",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "201", "application/json"):
            return unmarshal_json_response(models.DtoCustomerResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise models.errors.FlexpriceDefaultError(
            "Unexpected response received", http_res
        )

    async def create_customer_async(
        self,
        *,
        external_id: str,
        address_city: Optional[str] = None,
        address_country: Optional[str] = None,
        address_line1: Optional[str] = None,
        address_line2: Optional[str] = None,
        address_postal_code: Optional[str] = None,
        address_state: Optional[str] = None,
        email: Optional[str] = None,
        integration_entity_mapping: Optional[
            Union[
                List[models.DtoIntegrationEntityMapping],
                List[models.DtoIntegrationEntityMappingTypedDict],
            ]
        ] = None,
        metadata: Optional[Dict[str, str]] = None,
        name: Optional[str] = None,
        parent_customer_external_id: Optional[str] = None,
        parent_customer_id: Optional[str] = None,
        skip_onboarding_workflow: Optional[bool] = None,
        tax_rate_overrides: Optional[
            Union[
                List[models.DtoTaxRateOverride],
                List[models.DtoTaxRateOverrideTypedDict],
            ]
        ] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.DtoCustomerResponse:
        r"""Create customer

        Use when onboarding a new billing customer (e.g. sign-up or CRM sync). Ideal for linking via external_customer_id to your app's user id.

        :param external_id: external_id is the unique identifier from your system to reference this customer (required)
        :param address_city: address_city is the city name with maximum 100 characters
        :param address_country: address_country is the two-letter ISO 3166-1 alpha-2 country code
        :param address_line1: address_line1 is the primary address line with maximum 255 characters
        :param address_line2: address_line2 is the secondary address line with maximum 255 characters
        :param address_postal_code: address_postal_code is the ZIP code or postal code with maximum 20 characters
        :param address_state: address_state is the state, province, or region name with maximum 100 characters
        :param email: email is the customer's email address and must be a valid email format if provided
        :param integration_entity_mapping: integration_entity_mapping contains provider integration mappings for this customer
        :param metadata: metadata contains additional key-value pairs for storing extra information
        :param name: name is the full name or company name of the customer
        :param parent_customer_external_id: parent_customer_external_id is the external ID of the parent customer from your system
            Exactly one of parent_customer_id or parent_customer_external_id may be provided
        :param parent_customer_id: parent_customer_id is the internal FlexPrice ID of the parent customer
        :param skip_onboarding_workflow: skip_onboarding_workflow when true, prevents the customer onboarding workflow from being triggered
            This is used internally when a customer is created via a workflow to prevent infinite loops
            Default: false
        :param tax_rate_overrides: tax_rate_overrides contains tax rate configurations to be linked to this customer
        :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.DtoCreateCustomerRequest(
            address_city=address_city,
            address_country=address_country,
            address_line1=address_line1,
            address_line2=address_line2,
            address_postal_code=address_postal_code,
            address_state=address_state,
            email=email,
            external_id=external_id,
            integration_entity_mapping=utils.get_pydantic_model(
                integration_entity_mapping,
                Optional[List[models.DtoIntegrationEntityMapping]],
            ),
            metadata=metadata,
            name=name,
            parent_customer_external_id=parent_customer_external_id,
            parent_customer_id=parent_customer_id,
            skip_onboarding_workflow=skip_onboarding_workflow,
            tax_rate_overrides=utils.get_pydantic_model(
                tax_rate_overrides, Optional[List[models.DtoTaxRateOverride]]
            ),
        )

        req = self._build_request_async(
            method="POST",
            path="/customers",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request, False, False, "json", models.DtoCreateCustomerRequest
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="createCustomer",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "201", "application/json"):
            return unmarshal_json_response(models.DtoCustomerResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise models.errors.FlexpriceDefaultError(
            "Unexpected response received", http_res
        )

    def get_customer_by_external_id(
        self,
        *,
        external_id: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.DtoCustomerResponse:
        r"""Get customer by external ID

        Use when resolving a customer by your app's id (e.g. from your user table). Ideal for integrations that key by external id.

        :param external_id: Customer External ID
        :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.GetCustomerByExternalIDRequest(
            external_id=external_id,
        )

        req = self._build_request(
            method="GET",
            path="/customers/external/{external_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/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

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

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.DtoCustomerResponse, http_res)
        if utils.match_response(http_res, ["400", "404"], "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise models.errors.FlexpriceDefaultError(
            "Unexpected response received", http_res
        )

    async def get_customer_by_external_id_async(
        self,
        *,
        external_id: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.DtoCustomerResponse:
        r"""Get customer by external ID

        Use when resolving a customer by your app's id (e.g. from your user table). Ideal for integrations that key by external id.

        :param external_id: Customer External ID
        :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.GetCustomerByExternalIDRequest(
            external_id=external_id,
        )

        req = self._build_request_async(
            method="GET",
            path="/customers/external/{external_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/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

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

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.DtoCustomerResponse, http_res)
        if utils.match_response(http_res, ["400", "404"], "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise models.errors.FlexpriceDefaultError(
            "Unexpected response received", http_res
        )

    def query_customer(
        self,
        *,
        customer_ids: Optional[List[str]] = None,
        email: Optional[str] = None,
        end_time: Optional[str] = None,
        expand: Optional[str] = None,
        external_id: Optional[str] = None,
        external_ids: Optional[List[str]] = None,
        filters: Optional[
            Union[List[models.FilterCondition], List[models.FilterConditionTypedDict]]
        ] = None,
        limit: Optional[int] = None,
        offset: Optional[int] = None,
        order: Optional[models.CustomerFilterOrder] = None,
        parent_customer_ids: Optional[List[str]] = None,
        sort: Optional[
            Union[List[models.SortCondition], List[models.SortConditionTypedDict]]
        ] = None,
        start_time: Optional[str] = None,
        status: Optional[models.Status] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.DtoListCustomersResponse:
        r"""Query customers

        Use when listing or searching customers (e.g. admin CRM or reporting). Returns a paginated list; supports filtering and sorting.

        :param customer_ids:
        :param email:
        :param end_time:
        :param expand:
        :param external_id:
        :param external_ids:
        :param filters:
        :param limit:
        :param offset:
        :param order:
        :param parent_customer_ids:
        :param sort:
        :param start_time:
        :param status:
        :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.CustomerFilter(
            customer_ids=customer_ids,
            email=email,
            end_time=end_time,
            expand=expand,
            external_id=external_id,
            external_ids=external_ids,
            filters=utils.get_pydantic_model(
                filters, Optional[List[models.FilterCondition]]
            ),
            limit=limit,
            offset=offset,
            order=order,
            parent_customer_ids=parent_customer_ids,
            sort=utils.get_pydantic_model(sort, Optional[List[models.SortCondition]]),
            start_time=start_time,
            status=status,
        )

        req = self._build_request(
            method="POST",
            path="/customers/search",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request, False, False, "json", models.CustomerFilter
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="queryCustomer",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.DtoListCustomersResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise models.errors.FlexpriceDefaultError(
            "Unexpected response received", http_res
        )

    async def query_customer_async(
        self,
        *,
        customer_ids: Optional[List[str]] = None,
        email: Optional[str] = None,
        end_time: Optional[str] = None,
        expand: Optional[str] = None,
        external_id: Optional[str] = None,
        external_ids: Optional[List[str]] = None,
        filters: Optional[
            Union[List[models.FilterCondition], List[models.FilterConditionTypedDict]]
        ] = None,
        limit: Optional[int] = None,
        offset: Optional[int] = None,
        order: Optional[models.CustomerFilterOrder] = None,
        parent_customer_ids: Optional[List[str]] = None,
        sort: Optional[
            Union[List[models.SortCondition], List[models.SortConditionTypedDict]]
        ] = None,
        start_time: Optional[str] = None,
        status: Optional[models.Status] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.DtoListCustomersResponse:
        r"""Query customers

        Use when listing or searching customers (e.g. admin CRM or reporting). Returns a paginated list; supports filtering and sorting.

        :param customer_ids:
        :param email:
        :param end_time:
        :param expand:
        :param external_id:
        :param external_ids:
        :param filters:
        :param limit:
        :param offset:
        :param order:
        :param parent_customer_ids:
        :param sort:
        :param start_time:
        :param status:
        :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.CustomerFilter(
            customer_ids=customer_ids,
            email=email,
            end_time=end_time,
            expand=expand,
            external_id=external_id,
            external_ids=external_ids,
            filters=utils.get_pydantic_model(
                filters, Optional[List[models.FilterCondition]]
            ),
            limit=limit,
            offset=offset,
            order=order,
            parent_customer_ids=parent_customer_ids,
            sort=utils.get_pydantic_model(sort, Optional[List[models.SortCondition]]),
            start_time=start_time,
            status=status,
        )

        req = self._build_request_async(
            method="POST",
            path="/customers/search",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request, False, False, "json", models.CustomerFilter
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="queryCustomer",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.DtoListCustomersResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise models.errors.FlexpriceDefaultError(
            "Unexpected response received", http_res
        )

    def get_customer_usage_summary(
        self,
        *,
        customer_id: Optional[str] = None,
        customer_lookup_key: Optional[str] = None,
        feature_ids: Optional[List[str]] = None,
        feature_lookup_keys: Optional[List[str]] = None,
        subscription_ids: Optional[List[str]] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.DtoCustomerUsageSummaryResponse:
        r"""Get customer usage summary

        Use when showing a customer's usage (e.g. portal or overage alerts). Identify by customer_id or customer_lookup_key; supports filters.

        :param customer_id:
        :param customer_lookup_key:
        :param feature_ids:
        :param feature_lookup_keys:
        :param subscription_ids:
        :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.GetCustomerUsageSummaryRequest(
            customer_id=customer_id,
            customer_lookup_key=customer_lookup_key,
            feature_ids=feature_ids,
            feature_lookup_keys=feature_lookup_keys,
            subscription_ids=subscription_ids,
        )

        req = self._build_request(
            method="GET",
            path="/customers/usage",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getCustomerUsageSummary",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.DtoCustomerUsageSummaryResponse, http_res
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise models.errors.FlexpriceDefaultError(
            "Unexpected response received", http_res
        )

    async def get_customer_usage_summary_async(
        self,
        *,
        customer_id: Optional[str] = None,
        customer_lookup_key: Optional[str] = None,
        feature_ids: Optional[List[str]] = None,
        feature_lookup_keys: Optional[List[str]] = None,
        subscription_ids: Optional[List[str]] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.DtoCustomerUsageSummaryResponse:
        r"""Get customer usage summary

        Use when showing a customer's usage (e.g. portal or overage alerts). Identify by customer_id or customer_lookup_key; supports filters.

        :param customer_id:
        :param customer_lookup_key:
        :param feature_ids:
        :param feature_lookup_keys:
        :param subscription_ids:
        :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.GetCustomerUsageSummaryRequest(
            customer_id=customer_id,
            customer_lookup_key=customer_lookup_key,
            feature_ids=feature_ids,
            feature_lookup_keys=feature_lookup_keys,
            subscription_ids=subscription_ids,
        )

        req = self._build_request_async(
            method="GET",
            path="/customers/usage",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getCustomerUsageSummary",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.DtoCustomerUsageSummaryResponse, http_res
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise models.errors.FlexpriceDefaultError(
            "Unexpected response received", http_res
        )

    def get_customer(
        self,
        *,
        id: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.DtoCustomerResponse:
        r"""Get customer

        Use when you need to load a single customer (e.g. for a billing portal or to attach a subscription).

        :param id: Customer ID
        :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.GetCustomerRequest(
            id=id,
        )

        req = self._build_request(
            method="GET",
            path="/customers/{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/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getCustomer",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.DtoCustomerResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise models.errors.FlexpriceDefaultError(
            "Unexpected response received", http_res
        )

    async def get_customer_async(
        self,
        *,
        id: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.DtoCustomerResponse:
        r"""Get customer

        Use when you need to load a single customer (e.g. for a billing portal or to attach a subscription).

        :param id: Customer ID
        :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.GetCustomerRequest(
            id=id,
        )

        req = self._build_request_async(
            method="GET",
            path="/customers/{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/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getCustomer",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.DtoCustomerResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise models.errors.FlexpriceDefaultError(
            "Unexpected response received", http_res
        )

    def delete_customer(
        self,
        *,
        id: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ):
        r"""Delete customer

        Use when removing a customer (e.g. GDPR or churn). Returns 204 No Content on success.

        :param id: Customer ID
        :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.DeleteCustomerRequest(
            id=id,
        )

        req = self._build_request(
            method="DELETE",
            path="/customers/{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/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="deleteCustomer",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "204", "*"):
            return
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise models.errors.FlexpriceDefaultError(
            "Unexpected response received", http_res
        )

    async def delete_customer_async(
        self,
        *,
        id: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ):
        r"""Delete customer

        Use when removing a customer (e.g. GDPR or churn). Returns 204 No Content on success.

        :param id: Customer ID
        :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.DeleteCustomerRequest(
            id=id,
        )

        req = self._build_request_async(
            method="DELETE",
            path="/customers/{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/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="deleteCustomer",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "204", "*"):
            return
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise models.errors.FlexpriceDefaultError(
            "Unexpected response received", http_res
        )

    def get_customer_entitlements(
        self,
        *,
        id: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.DtoCustomerEntitlementsResponse:
        r"""Get customer entitlements

        Use when checking what a customer can access (e.g. feature gating or usage limits). Supports optional filters (feature_ids, subscription_ids).

        :param id: Customer ID
        :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.GetCustomerEntitlementsRequest(
            id=id,
        )

        req = self._build_request(
            method="GET",
            path="/customers/{id}/entitlements",
            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/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getCustomerEntitlements",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.DtoCustomerEntitlementsResponse, http_res
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise models.errors.FlexpriceDefaultError(
            "Unexpected response received", http_res
        )

    async def get_customer_entitlements_async(
        self,
        *,
        id: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.DtoCustomerEntitlementsResponse:
        r"""Get customer entitlements

        Use when checking what a customer can access (e.g. feature gating or usage limits). Supports optional filters (feature_ids, subscription_ids).

        :param id: Customer ID
        :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.GetCustomerEntitlementsRequest(
            id=id,
        )

        req = self._build_request_async(
            method="GET",
            path="/customers/{id}/entitlements",
            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/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getCustomerEntitlements",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.DtoCustomerEntitlementsResponse, http_res
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise models.errors.FlexpriceDefaultError(
            "Unexpected response received", http_res
        )

    def get_customer_upcoming_grants(
        self,
        *,
        id: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.DtoListCreditGrantApplicationsResponse:
        r"""Get upcoming credit grant applications

        Use when showing upcoming or pending credits for a customer (e.g. in a portal or for forecasting).

        :param id: Customer ID
        :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.GetCustomerUpcomingGrantsRequest(
            id=id,
        )

        req = self._build_request(
            method="GET",
            path="/customers/{id}/grants/upcoming",
            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/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

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

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.DtoListCreditGrantApplicationsResponse, http_res
            )
        if utils.match_response(http_res, ["400", "404"], "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise models.errors.FlexpriceDefaultError(
            "Unexpected response received", http_res
        )

    async def get_customer_upcoming_grants_async(
        self,
        *,
        id: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.DtoListCreditGrantApplicationsResponse:
        r"""Get upcoming credit grant applications

        Use when showing upcoming or pending credits for a customer (e.g. in a portal or for forecasting).

        :param id: Customer ID
        :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.GetCustomerUpcomingGrantsRequest(
            id=id,
        )

        req = self._build_request_async(
            method="GET",
            path="/customers/{id}/grants/upcoming",
            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/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

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

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.DtoListCreditGrantApplicationsResponse, http_res
            )
        if utils.match_response(http_res, ["400", "404"], "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                models.errors.ErrorsErrorResponseData, http_res
            )
            raise models.errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise models.errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise models.errors.FlexpriceDefaultError(
            "Unexpected response received", http_res
        )
