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

from __future__ import annotations
from .dto_integrationentitymapping import (
    DtoIntegrationEntityMapping,
    DtoIntegrationEntityMappingTypedDict,
)
from .dto_taxrateoverride import DtoTaxRateOverride, DtoTaxRateOverrideTypedDict
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, List, Optional
from typing_extensions import NotRequired, TypedDict


class DtoCreateCustomerRequestTypedDict(TypedDict):
    r"""Request object for creating a new customer in the system"""

    external_id: str
    r"""external_id is the unique identifier from your system to reference this customer (required)"""
    address_city: NotRequired[str]
    r"""address_city is the city name with maximum 100 characters"""
    address_country: NotRequired[str]
    r"""address_country is the two-letter ISO 3166-1 alpha-2 country code"""
    address_line1: NotRequired[str]
    r"""address_line1 is the primary address line with maximum 255 characters"""
    address_line2: NotRequired[str]
    r"""address_line2 is the secondary address line with maximum 255 characters"""
    address_postal_code: NotRequired[str]
    r"""address_postal_code is the ZIP code or postal code with maximum 20 characters"""
    address_state: NotRequired[str]
    r"""address_state is the state, province, or region name with maximum 100 characters"""
    email: NotRequired[str]
    r"""email is the customer's email address and must be a valid email format if provided"""
    integration_entity_mapping: NotRequired[List[DtoIntegrationEntityMappingTypedDict]]
    r"""integration_entity_mapping contains provider integration mappings for this customer"""
    metadata: NotRequired[Dict[str, str]]
    r"""metadata contains additional key-value pairs for storing extra information"""
    name: NotRequired[str]
    r"""name is the full name or company name of the customer"""
    parent_customer_external_id: NotRequired[str]
    r"""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
    """
    parent_customer_id: NotRequired[str]
    r"""parent_customer_id is the internal FlexPrice ID of the parent customer"""
    skip_onboarding_workflow: NotRequired[bool]
    r"""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
    """
    tax_rate_overrides: NotRequired[List[DtoTaxRateOverrideTypedDict]]
    r"""tax_rate_overrides contains tax rate configurations to be linked to this customer"""


class DtoCreateCustomerRequest(BaseModel):
    r"""Request object for creating a new customer in the system"""

    external_id: str
    r"""external_id is the unique identifier from your system to reference this customer (required)"""

    address_city: Optional[str] = None
    r"""address_city is the city name with maximum 100 characters"""

    address_country: Optional[str] = None
    r"""address_country is the two-letter ISO 3166-1 alpha-2 country code"""

    address_line1: Optional[str] = None
    r"""address_line1 is the primary address line with maximum 255 characters"""

    address_line2: Optional[str] = None
    r"""address_line2 is the secondary address line with maximum 255 characters"""

    address_postal_code: Optional[str] = None
    r"""address_postal_code is the ZIP code or postal code with maximum 20 characters"""

    address_state: Optional[str] = None
    r"""address_state is the state, province, or region name with maximum 100 characters"""

    email: Optional[str] = None
    r"""email is the customer's email address and must be a valid email format if provided"""

    integration_entity_mapping: Optional[List[DtoIntegrationEntityMapping]] = None
    r"""integration_entity_mapping contains provider integration mappings for this customer"""

    metadata: Optional[Dict[str, str]] = None
    r"""metadata contains additional key-value pairs for storing extra information"""

    name: Optional[str] = None
    r"""name is the full name or company name of the customer"""

    parent_customer_external_id: Optional[str] = None
    r"""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
    """

    parent_customer_id: Optional[str] = None
    r"""parent_customer_id is the internal FlexPrice ID of the parent customer"""

    skip_onboarding_workflow: Optional[bool] = None
    r"""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
    """

    tax_rate_overrides: Optional[List[DtoTaxRateOverride]] = None
    r"""tax_rate_overrides contains tax rate configurations to be linked to this customer"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "address_city",
                "address_country",
                "address_line1",
                "address_line2",
                "address_postal_code",
                "address_state",
                "email",
                "integration_entity_mapping",
                "metadata",
                "name",
                "parent_customer_external_id",
                "parent_customer_id",
                "skip_onboarding_workflow",
                "tax_rate_overrides",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m
