"""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 paygentic_sdk.types import BaseModel, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import Dict, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


class ConsumerTypedDict(TypedDict):
    r"""Fields to create a new consumer. Will use an existing consumer if one exists with the same email address. Required if `consumerId` is not provided. Address with complete tax information (country, state, zipCode) is required for tax calculation when using Paygentic Tax."""

    name: str
    email: str
    r"""Consumer email address. Sample values: 'customer@example.com', 'billing@company.com', 'admin@startup.io'"""
    address: AddressTypedDict
    r"""Consumer address. For accurate tax calculation when using Paygentic Tax, provide complete address with country (ISO 3166-1 alpha-2), state, and zipCode. Incomplete addresses will skip tax calculation and use the plan's default tax rate instead."""
    phone: NotRequired[str]
    r"""Consumer phone number. Sample values: '+1-555-123-4567', '+44-20-7946-0958', '+49-30-12345678'"""


class Consumer(BaseModel):
    r"""Fields to create a new consumer. Will use an existing consumer if one exists with the same email address. Required if `consumerId` is not provided. Address with complete tax information (country, state, zipCode) is required for tax calculation when using Paygentic Tax."""

    name: str

    email: str
    r"""Consumer email address. Sample values: 'customer@example.com', 'billing@company.com', 'admin@startup.io'"""

    address: Address
    r"""Consumer address. For accurate tax calculation when using Paygentic Tax, provide complete address with country (ISO 3166-1 alpha-2), state, and zipCode. Incomplete addresses will skip tax calculation and use the plan's default tax rate instead."""

    phone: Optional[str] = None
    r"""Consumer phone number. Sample values: '+1-555-123-4567', '+44-20-7946-0958', '+49-30-12345678'"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["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 CreateCustomerRequestTypedDict(TypedDict):
    merchant_id: str
    r"""Unique identifier for an organization"""
    consumer: NotRequired[ConsumerTypedDict]
    r"""Fields to create a new consumer. Will use an existing consumer if one exists with the same email address. Required if `consumerId` is not provided. Address with complete tax information (country, state, zipCode) is required for tax calculation when using Paygentic Tax."""
    consumer_id: NotRequired[str]
    r"""Unique identifier for an organization"""
    tax_id: NotRequired[str]
    r"""Optional business tax registration identifier. Sample values: 'GB123456789' for UK VAT, 'DE123456789' for German VAT, 'FR12345678901' for French VAT. Supplying this value 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 CreateCustomerRequest(BaseModel):
    merchant_id: Annotated[str, pydantic.Field(alias="merchantId")]
    r"""Unique identifier for an organization"""

    consumer: Optional[Consumer] = None
    r"""Fields to create a new consumer. Will use an existing consumer if one exists with the same email address. Required if `consumerId` is not provided. Address with complete tax information (country, state, zipCode) is required for tax calculation when using Paygentic Tax."""

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

    tax_id: Annotated[Optional[str], pydantic.Field(alias="taxId")] = None
    r"""Optional business tax registration identifier. Sample values: 'GB123456789' for UK VAT, 'DE123456789' for German VAT, 'FR12345678901' for French VAT. Supplying this value 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(["consumer", "consumerId", "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


class CreateCustomerResponseBody2TypedDict(TypedDict):
    r"""Customer created successfully"""

    customer_id: str
    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."""


class CreateCustomerResponseBody2(BaseModel):
    r"""Customer created successfully"""

    customer_id: Annotated[str, pydantic.Field(alias="customerId")]

    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."""


class CreateCustomerResponseBody1TypedDict(TypedDict):
    r"""Customer already exists"""

    customer_id: str
    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."""


class CreateCustomerResponseBody1(BaseModel):
    r"""Customer already exists"""

    customer_id: Annotated[str, pydantic.Field(alias="customerId")]

    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."""


CreateCustomerResponseTypedDict = TypeAliasType(
    "CreateCustomerResponseTypedDict",
    Union[CreateCustomerResponseBody1TypedDict, CreateCustomerResponseBody2TypedDict],
)


CreateCustomerResponse = TypeAliasType(
    "CreateCustomerResponse",
    Union[CreateCustomerResponseBody1, CreateCustomerResponseBody2],
)


try:
    CreateCustomerRequest.model_rebuild()
except NameError:
    pass
try:
    CreateCustomerResponseBody2.model_rebuild()
except NameError:
    pass
try:
    CreateCustomerResponseBody1.model_rebuild()
except NameError:
    pass
