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

from __future__ import annotations
from .types_status import TypesStatus
from .types_taxratescope import TypesTaxRateScope
from .types_taxratestatus import TypesTaxRateStatus
from .types_taxratetype import TypesTaxRateType
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 DtoTaxRateResponseTypedDict(TypedDict):
    code: NotRequired[str]
    created_at: NotRequired[str]
    created_by: NotRequired[str]
    description: NotRequired[str]
    environment_id: NotRequired[str]
    fixed_value: NotRequired[str]
    id: NotRequired[str]
    metadata: NotRequired[Dict[str, str]]
    name: NotRequired[str]
    percentage_value: NotRequired[str]
    scope: NotRequired[TypesTaxRateScope]
    status: NotRequired[TypesStatus]
    tax_rate_status: NotRequired[TypesTaxRateStatus]
    tax_rate_type: NotRequired[TypesTaxRateType]
    tenant_id: NotRequired[str]
    updated_at: NotRequired[str]
    updated_by: NotRequired[str]


class DtoTaxRateResponse(BaseModel):
    code: Optional[str] = None

    created_at: Optional[str] = None

    created_by: Optional[str] = None

    description: Optional[str] = None

    environment_id: Optional[str] = None

    fixed_value: Optional[str] = None

    id: Optional[str] = None

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

    name: Optional[str] = None

    percentage_value: Optional[str] = None

    scope: Optional[TypesTaxRateScope] = None

    status: Optional[TypesStatus] = None

    tax_rate_status: Optional[TypesTaxRateStatus] = None

    tax_rate_type: Optional[TypesTaxRateType] = 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(
            [
                "code",
                "created_at",
                "created_by",
                "description",
                "environment_id",
                "fixed_value",
                "id",
                "metadata",
                "name",
                "percentage_value",
                "scope",
                "status",
                "tax_rate_status",
                "tax_rate_type",
                "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
