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

from __future__ import annotations
from .invoicelineitem import InvoiceLineItem, InvoiceLineItemTypedDict
from paygentic_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
import pydantic
from pydantic import model_serializer
from typing import List
from typing_extensions import Annotated, NotRequired, TypedDict


class InvoiceLineItemsResponseTypedDict(TypedDict):
    invoice_id: str
    r"""The invoice ID"""
    line_items: List[InvoiceLineItemTypedDict]
    r"""Array of line items for this page"""
    total_count: int
    r"""Total number of line items across all pages"""
    next_page_token: NotRequired[Nullable[str]]
    r"""Token for fetching the next page, null if no more pages"""


class InvoiceLineItemsResponse(BaseModel):
    invoice_id: Annotated[str, pydantic.Field(alias="invoiceId")]
    r"""The invoice ID"""

    line_items: Annotated[List[InvoiceLineItem], pydantic.Field(alias="lineItems")]
    r"""Array of line items for this page"""

    total_count: Annotated[int, pydantic.Field(alias="totalCount")]
    r"""Total number of line items across all pages"""

    next_page_token: Annotated[
        OptionalNullable[str], pydantic.Field(alias="nextPageToken")
    ] = UNSET
    r"""Token for fetching the next page, null if no more pages"""

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

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            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:
    InvoiceLineItemsResponse.model_rebuild()
except NameError:
    pass
