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

from __future__ import annotations
from .dto_integrationentitymapping import (
    DtoIntegrationEntityMapping,
    DtoIntegrationEntityMappingTypedDict,
)
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 DtoUpdateCustomerRequestTypedDict(TypedDict):
    r"""Request object for updating an existing customer. All fields are optional - only provided fields will be updated"""

    address_city: NotRequired[str]
    r"""address_city is the updated city name with maximum 100 characters"""
    address_country: NotRequired[str]
    r"""address_country is the updated two-letter ISO 3166-1 alpha-2 country code"""
    address_line1: NotRequired[str]
    r"""address_line1 is the updated primary address line with maximum 255 characters"""
    address_line2: NotRequired[str]
    r"""address_line2 is the updated secondary address line with maximum 255 characters"""
    address_postal_code: NotRequired[str]
    r"""address_postal_code is the updated postal code with maximum 20 characters"""
    address_state: NotRequired[str]
    r"""address_state is the updated state, province, or region name with maximum 100 characters"""
    email: NotRequired[str]
    r"""email is the updated email address and must be a valid email format if provided"""
    external_id: NotRequired[str]
    r"""external_id is the updated external identifier for the customer"""
    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 updated key-value pairs that will replace existing metadata"""
    name: NotRequired[str]
    r"""name is the updated name or company name for 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
    If you provide the external ID, the parent customer value will be ignored
    """
    parent_customer_id: NotRequired[str]
    r"""parent_customer_id is the internal FlexPrice ID of the parent customer"""


class DtoUpdateCustomerRequest(BaseModel):
    r"""Request object for updating an existing customer. All fields are optional - only provided fields will be updated"""

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

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

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

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

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

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

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

    external_id: Optional[str] = None
    r"""external_id is the updated external identifier for the customer"""

    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 updated key-value pairs that will replace existing metadata"""

    name: Optional[str] = None
    r"""name is the updated name or company name for 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
    If you provide the external ID, the parent customer value will be ignored
    """

    parent_customer_id: Optional[str] = None
    r"""parent_customer_id is the internal FlexPrice ID of the parent 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",
                "external_id",
                "integration_entity_mapping",
                "metadata",
                "name",
                "parent_customer_external_id",
                "parent_customer_id",
            ]
        )
        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
