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

from __future__ import annotations
from flexprice_py.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Optional
from typing_extensions import NotRequired, TypedDict


class PricePriceTierTypedDict(TypedDict):
    flat_amount: NotRequired[str]
    r"""flat_amount is the flat amount for the given tier (optional)
    Applied on top of unit_amount*quantity. Useful for cases like \"2.7$ + 5c\" 
    """
    unit_amount: NotRequired[str]
    r"""unit_amount is the amount per unit for the given tier"""
    up_to: NotRequired[int]
    r"""up_to is the quantity up to which this tier applies. It is null for the last tier.
    IMPORTANT: Tier boundaries are INCLUSIVE.
    - If up_to is 1000, then quantity less than or equal to 1000 belongs to this tier
    - This behavior is consistent across both VOLUME and SLAB tier modes
    """


class PricePriceTier(BaseModel):
    flat_amount: Optional[str] = None
    r"""flat_amount is the flat amount for the given tier (optional)
    Applied on top of unit_amount*quantity. Useful for cases like \"2.7$ + 5c\" 
    """

    unit_amount: Optional[str] = None
    r"""unit_amount is the amount per unit for the given tier"""

    up_to: Optional[int] = None
    r"""up_to is the quantity up to which this tier applies. It is null for the last tier.
    IMPORTANT: Tier boundaries are INCLUSIVE.
    - If up_to is 1000, then quantity less than or equal to 1000 belongs to this tier
    - This behavior is consistent across both VOLUME and SLAB tier modes
    """

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["flat_amount", "unit_amount", "up_to"])
        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
