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

from __future__ import annotations
from .dto_taxrateresponse import DtoTaxRateResponse, DtoTaxRateResponseTypedDict
from .status import Status
from .taxrateentitytype import TaxRateEntityType
from flexprice_py.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, Optional
from typing_extensions import NotRequired, TypedDict


class DtoTaxAppliedResponseTypedDict(TypedDict):
    applied_at: NotRequired[str]
    created_at: NotRequired[str]
    created_by: NotRequired[str]
    currency: NotRequired[str]
    entity_id: NotRequired[str]
    entity_type: NotRequired[TaxRateEntityType]
    environment_id: NotRequired[str]
    id: NotRequired[str]
    idempotency_key: NotRequired[str]
    metadata: NotRequired[Dict[str, str]]
    status: NotRequired[Status]
    tax_amount: NotRequired[str]
    tax_association_id: NotRequired[str]
    tax_rate: NotRequired[DtoTaxRateResponseTypedDict]
    tax_rate_id: NotRequired[str]
    taxable_amount: NotRequired[str]
    tenant_id: NotRequired[str]
    updated_at: NotRequired[str]
    updated_by: NotRequired[str]


class DtoTaxAppliedResponse(BaseModel):
    applied_at: Optional[str] = None

    created_at: Optional[str] = None

    created_by: Optional[str] = None

    currency: Optional[str] = None

    entity_id: Optional[str] = None

    entity_type: Optional[TaxRateEntityType] = None

    environment_id: Optional[str] = None

    id: Optional[str] = None

    idempotency_key: Optional[str] = None

    metadata: Optional[Dict[str, str]] = None

    status: Optional[Status] = None

    tax_amount: Optional[str] = None

    tax_association_id: Optional[str] = None

    tax_rate: Optional[DtoTaxRateResponse] = None

    tax_rate_id: Optional[str] = None

    taxable_amount: Optional[str] = None

    tenant_id: Optional[str] = None

    updated_at: Optional[str] = None

    updated_by: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "applied_at",
                "created_at",
                "created_by",
                "currency",
                "entity_id",
                "entity_type",
                "environment_id",
                "id",
                "idempotency_key",
                "metadata",
                "status",
                "tax_amount",
                "tax_association_id",
                "tax_rate",
                "tax_rate_id",
                "taxable_amount",
                "tenant_id",
                "updated_at",
                "updated_by",
            ]
        )
        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
