"""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 DtoTaxAssociationResponseTypedDict(TypedDict):
    auto_apply: NotRequired[bool]
    r"""Whether this tax should be automatically applied"""
    created_at: NotRequired[str]
    created_by: NotRequired[str]
    currency: NotRequired[str]
    r"""Currency"""
    entity_id: NotRequired[str]
    r"""ID of the entity this tax rate applies to"""
    entity_type: NotRequired[TaxRateEntityType]
    environment_id: NotRequired[str]
    r"""EnvironmentID is the ID of the environment this tax rate config belongs to"""
    id: NotRequired[str]
    r"""ID of the ent."""
    metadata: NotRequired[Dict[str, str]]
    r"""Metadata holds the value of the \"metadata\" field."""
    priority: NotRequired[int]
    r"""Priority for tax resolution (lower number = higher priority)"""
    status: NotRequired[Status]
    tax_rate: NotRequired[DtoTaxRateResponseTypedDict]
    tax_rate_id: NotRequired[str]
    r"""Reference to the TaxRate entity"""
    tenant_id: NotRequired[str]
    updated_at: NotRequired[str]
    updated_by: NotRequired[str]


class DtoTaxAssociationResponse(BaseModel):
    auto_apply: Optional[bool] = None
    r"""Whether this tax should be automatically applied"""

    created_at: Optional[str] = None

    created_by: Optional[str] = None

    currency: Optional[str] = None
    r"""Currency"""

    entity_id: Optional[str] = None
    r"""ID of the entity this tax rate applies to"""

    entity_type: Optional[TaxRateEntityType] = None

    environment_id: Optional[str] = None
    r"""EnvironmentID is the ID of the environment this tax rate config belongs to"""

    id: Optional[str] = None
    r"""ID of the ent."""

    metadata: Optional[Dict[str, str]] = None
    r"""Metadata holds the value of the \"metadata\" field."""

    priority: Optional[int] = None
    r"""Priority for tax resolution (lower number = higher priority)"""

    status: Optional[Status] = None

    tax_rate: Optional[DtoTaxRateResponse] = None

    tax_rate_id: Optional[str] = None
    r"""Reference to the TaxRate entity"""

    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(
            [
                "auto_apply",
                "created_at",
                "created_by",
                "currency",
                "entity_id",
                "entity_type",
                "environment_id",
                "id",
                "metadata",
                "priority",
                "status",
                "tax_rate",
                "tax_rate_id",
                "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
