"""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 DtoInvoiceLineItemPreviewTypedDict(TypedDict):
    amount: NotRequired[str]
    r"""amount for this line item"""
    description: NotRequired[str]
    r"""description of the line item"""
    is_proration: NotRequired[bool]
    r"""is_proration indicates if this line item is a proration"""
    period_end: NotRequired[str]
    r"""period_end for this line item (if applicable)"""
    period_start: NotRequired[str]
    r"""period_start for this line item (if applicable)"""
    quantity: NotRequired[str]
    r"""quantity for this line item"""
    unit_price: NotRequired[str]
    r"""unit_price for this line item"""


class DtoInvoiceLineItemPreview(BaseModel):
    amount: Optional[str] = None
    r"""amount for this line item"""

    description: Optional[str] = None
    r"""description of the line item"""

    is_proration: Optional[bool] = None
    r"""is_proration indicates if this line item is a proration"""

    period_end: Optional[str] = None
    r"""period_end for this line item (if applicable)"""

    period_start: Optional[str] = None
    r"""period_start for this line item (if applicable)"""

    quantity: Optional[str] = None
    r"""quantity for this line item"""

    unit_price: Optional[str] = None
    r"""unit_price for this line item"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "amount",
                "description",
                "is_proration",
                "period_end",
                "period_start",
                "quantity",
                "unit_price",
            ]
        )
        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
