"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
# @generated-id: c19981e32086

from __future__ import annotations
from .amount import Amount, AmountTypedDict
from .sales_invoice_discount_response import (
    SalesInvoiceDiscountResponse,
    SalesInvoiceDiscountResponseTypedDict,
)
from mollie.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing_extensions import Annotated, NotRequired, TypedDict


class SalesInvoiceLineItemResponseTypedDict(TypedDict):
    description: str
    r"""A description of the line item. For example *LEGO 4440 Forest Police Station*."""
    quantity: int
    r"""The number of items."""
    vat_rate: str
    r"""The vat rate to be applied to this line item."""
    unit_price: AmountTypedDict
    r"""In v2 endpoints, monetary amounts are represented as objects with a `currency` and `value` field."""
    discount: NotRequired[Nullable[SalesInvoiceDiscountResponseTypedDict]]


class SalesInvoiceLineItemResponse(BaseModel):
    description: str
    r"""A description of the line item. For example *LEGO 4440 Forest Police Station*."""

    quantity: int
    r"""The number of items."""

    vat_rate: Annotated[str, pydantic.Field(alias="vatRate")]
    r"""The vat rate to be applied to this line item."""

    unit_price: Annotated[Amount, pydantic.Field(alias="unitPrice")]
    r"""In v2 endpoints, monetary amounts are represented as objects with a `currency` and `value` field."""

    discount: OptionalNullable[SalesInvoiceDiscountResponse] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["discount"])
        nullable_fields = set(["discount"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m


try:
    SalesInvoiceLineItemResponse.model_rebuild()
except NameError:
    pass
