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

from __future__ import annotations
from .taxratescope import TaxRateScope
from .taxratetype import TaxRateType
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 DtoCreateTaxRateRequestTypedDict(TypedDict):
    code: str
    r"""code is the unique alphanumeric case sensitive identifier for the tax rate (required)"""
    name: str
    r"""name is the human-readable name for the tax rate (required)"""
    description: NotRequired[str]
    r"""description is an optional text description providing details about the tax rate"""
    fixed_value: NotRequired[str]
    r"""fixed_value is the fixed monetary amount when tax_rate_type is \"fixed\" """
    metadata: NotRequired[Dict[str, str]]
    r"""metadata contains additional key-value pairs for storing extra information"""
    percentage_value: NotRequired[str]
    r"""percentage_value is the percentage value (0-100) when tax_rate_type is \"percentage\" """
    scope: NotRequired[TaxRateScope]
    tax_rate_type: NotRequired[TaxRateType]


class DtoCreateTaxRateRequest(BaseModel):
    code: str
    r"""code is the unique alphanumeric case sensitive identifier for the tax rate (required)"""

    name: str
    r"""name is the human-readable name for the tax rate (required)"""

    description: Optional[str] = None
    r"""description is an optional text description providing details about the tax rate"""

    fixed_value: Optional[str] = None
    r"""fixed_value is the fixed monetary amount when tax_rate_type is \"fixed\" """

    metadata: Optional[Dict[str, str]] = None
    r"""metadata contains additional key-value pairs for storing extra information"""

    percentage_value: Optional[str] = None
    r"""percentage_value is the percentage value (0-100) when tax_rate_type is \"percentage\" """

    scope: Optional[TaxRateScope] = None

    tax_rate_type: Optional[TaxRateType] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "description",
                "fixed_value",
                "metadata",
                "percentage_value",
                "scope",
                "tax_rate_type",
            ]
        )
        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
