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

from __future__ import annotations
from .address import Address, AddressTypedDict
from .validtaxaddress import ValidTaxAddress, ValidTaxAddressTypedDict
from datetime import datetime
from paygentic_sdk.types import BaseModel, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import Dict, Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


CustomerObject = Literal["customer",]


class CustomerOrganizationTypedDict(TypedDict):
    id: str
    name: str
    address: NotRequired[AddressTypedDict]
    billing_email: NotRequired[str]
    phone: NotRequired[str]


class CustomerOrganization(BaseModel):
    id: str

    name: str

    address: Optional[Address] = None

    billing_email: Annotated[Optional[str], pydantic.Field(alias="billingEmail")] = None

    phone: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["address", "billingEmail", "phone"])
        serialized = handler(self)
        m = {}

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

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

        return m


class CustomerTypedDict(TypedDict):
    id: str
    r"""Unique identifier for a customer"""
    consumer_id: str
    r"""Unique identifier for an organization"""
    created_at: datetime
    merchant_id: str
    r"""Unique identifier for an organization"""
    updated_at: datetime
    valid_tax_address: ValidTaxAddressTypedDict
    r"""Indicates whether the consumer address is valid for tax calculation when using Paygentic Tax. If valid=false, tax calculation will be skipped and internal invoice flow with default tax rate will be used."""
    object: NotRequired[CustomerObject]
    organization: NotRequired[CustomerOrganizationTypedDict]
    tax_id: NotRequired[str]
    r"""Business tax registration identifier. Sample values: 'GB123456789' for UK VAT, 'DE123456789' for German VAT, 'FR12345678901' for French VAT. Enables inter-company tax handling and exemption from standard tax collection."""
    tax_rates: NotRequired[Dict[str, float]]
    r"""An object mapping plan IDs, metric IDs, or 'default' to a tax rate percentage (e.g., 13 for 13%)"""


class Customer(BaseModel):
    id: str
    r"""Unique identifier for a customer"""

    consumer_id: Annotated[str, pydantic.Field(alias="consumerId")]
    r"""Unique identifier for an organization"""

    created_at: Annotated[datetime, pydantic.Field(alias="createdAt")]

    merchant_id: Annotated[str, pydantic.Field(alias="merchantId")]
    r"""Unique identifier for an organization"""

    updated_at: Annotated[datetime, pydantic.Field(alias="updatedAt")]

    valid_tax_address: Annotated[
        ValidTaxAddress, pydantic.Field(alias="validTaxAddress")
    ]
    r"""Indicates whether the consumer address is valid for tax calculation when using Paygentic Tax. If valid=false, tax calculation will be skipped and internal invoice flow with default tax rate will be used."""

    object: Optional[CustomerObject] = "customer"

    organization: Optional[CustomerOrganization] = None

    tax_id: Annotated[Optional[str], pydantic.Field(alias="taxId")] = None
    r"""Business tax registration identifier. Sample values: 'GB123456789' for UK VAT, 'DE123456789' for German VAT, 'FR12345678901' for French VAT. Enables inter-company tax handling and exemption from standard tax collection."""

    tax_rates: Annotated[
        Optional[Dict[str, float]], pydantic.Field(alias="taxRates")
    ] = None
    r"""An object mapping plan IDs, metric IDs, or 'default' to a tax rate percentage (e.g., 13 for 13%)"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["object", "organization", "taxId", "taxRates"])
        serialized = handler(self)
        m = {}

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

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

        return m


try:
    CustomerOrganization.model_rebuild()
except NameError:
    pass
try:
    Customer.model_rebuild()
except NameError:
    pass
