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

from __future__ import annotations
from .commitmentinfo import CommitmentInfo, CommitmentInfoTypedDict
from .dto_sourceusageitem import DtoSourceUsageItem, DtoSourceUsageItemTypedDict
from .dto_usagebreakdownitem import (
    DtoUsageBreakdownItem,
    DtoUsageBreakdownItemTypedDict,
)
from .status import Status
from flexprice_py.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, List, Optional
from typing_extensions import NotRequired, TypedDict


class DtoInvoiceLineItemResponseTypedDict(TypedDict):
    amount: NotRequired[str]
    commitment_info: NotRequired[CommitmentInfoTypedDict]
    created_at: NotRequired[str]
    created_by: NotRequired[str]
    currency: NotRequired[str]
    customer_id: NotRequired[str]
    display_name: NotRequired[str]
    entity_id: NotRequired[str]
    entity_type: NotRequired[str]
    environment_id: NotRequired[str]
    id: NotRequired[str]
    invoice_id: NotRequired[str]
    invoice_level_discount: NotRequired[str]
    r"""invoice_level_discount is the discount amount in invoice currency applied to all line items on the invoice."""
    line_item_discount: NotRequired[str]
    r"""line_item_discount is the discount amount in invoice currency applied directly to this line item."""
    metadata: NotRequired[Dict[str, str]]
    meter_display_name: NotRequired[str]
    meter_id: NotRequired[str]
    period_end: NotRequired[str]
    period_start: NotRequired[str]
    plan_display_name: NotRequired[str]
    prepaid_credits_applied: NotRequired[str]
    r"""prepaid_credits_applied is the amount in invoice currency reduced from this line item due to prepaid credits application."""
    price_id: NotRequired[str]
    price_type: NotRequired[str]
    price_unit: NotRequired[str]
    price_unit_amount: NotRequired[str]
    price_unit_id: NotRequired[str]
    quantity: NotRequired[str]
    status: NotRequired[Status]
    subscription_id: NotRequired[str]
    tenant_id: NotRequired[str]
    updated_at: NotRequired[str]
    updated_by: NotRequired[str]
    usage_analytics: NotRequired[List[DtoSourceUsageItemTypedDict]]
    r"""usage_analytics contains usage analytics for this line item (legacy - grouped by source)"""
    usage_breakdown: NotRequired[List[DtoUsageBreakdownItemTypedDict]]
    r"""usage_breakdown contains flexible usage breakdown for this line item (supports any grouping)"""


class DtoInvoiceLineItemResponse(BaseModel):
    amount: Optional[str] = None

    commitment_info: Optional[CommitmentInfo] = None

    created_at: Optional[str] = None

    created_by: Optional[str] = None

    currency: Optional[str] = None

    customer_id: Optional[str] = None

    display_name: Optional[str] = None

    entity_id: Optional[str] = None

    entity_type: Optional[str] = None

    environment_id: Optional[str] = None

    id: Optional[str] = None

    invoice_id: Optional[str] = None

    invoice_level_discount: Optional[str] = None
    r"""invoice_level_discount is the discount amount in invoice currency applied to all line items on the invoice."""

    line_item_discount: Optional[str] = None
    r"""line_item_discount is the discount amount in invoice currency applied directly to this line item."""

    metadata: Optional[Dict[str, str]] = None

    meter_display_name: Optional[str] = None

    meter_id: Optional[str] = None

    period_end: Optional[str] = None

    period_start: Optional[str] = None

    plan_display_name: Optional[str] = None

    prepaid_credits_applied: Optional[str] = None
    r"""prepaid_credits_applied is the amount in invoice currency reduced from this line item due to prepaid credits application."""

    price_id: Optional[str] = None

    price_type: Optional[str] = None

    price_unit: Optional[str] = None

    price_unit_amount: Optional[str] = None

    price_unit_id: Optional[str] = None

    quantity: Optional[str] = None

    status: Optional[Status] = None

    subscription_id: Optional[str] = None

    tenant_id: Optional[str] = None

    updated_at: Optional[str] = None

    updated_by: Optional[str] = None

    usage_analytics: Optional[List[DtoSourceUsageItem]] = None
    r"""usage_analytics contains usage analytics for this line item (legacy - grouped by source)"""

    usage_breakdown: Optional[List[DtoUsageBreakdownItem]] = None
    r"""usage_breakdown contains flexible usage breakdown for this line item (supports any grouping)"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "amount",
                "commitment_info",
                "created_at",
                "created_by",
                "currency",
                "customer_id",
                "display_name",
                "entity_id",
                "entity_type",
                "environment_id",
                "id",
                "invoice_id",
                "invoice_level_discount",
                "line_item_discount",
                "metadata",
                "meter_display_name",
                "meter_id",
                "period_end",
                "period_start",
                "plan_display_name",
                "prepaid_credits_applied",
                "price_id",
                "price_type",
                "price_unit",
                "price_unit_amount",
                "price_unit_id",
                "quantity",
                "status",
                "subscription_id",
                "tenant_id",
                "updated_at",
                "updated_by",
                "usage_analytics",
                "usage_breakdown",
            ]
        )
        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
