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

from __future__ import annotations
from .commitmentinfo import CommitmentInfo, CommitmentInfoTypedDict
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, Optional
from typing_extensions import NotRequired, TypedDict


class DtoCreateInvoiceLineItemRequestTypedDict(TypedDict):
    amount: str
    r"""amount is the monetary amount for this line item"""
    quantity: str
    r"""quantity is the quantity of units for this line item"""
    commitment_info: NotRequired[CommitmentInfoTypedDict]
    display_name: NotRequired[str]
    r"""display_name is the optional human-readable name for this line item"""
    entity_id: NotRequired[str]
    r"""entity_id is the optional unique identifier of the entity associated with this line item"""
    entity_type: NotRequired[str]
    r"""entity_type is the optional type of the entity associated with this line item"""
    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]
    r"""meter_display_name is the optional human-readable name of the meter"""
    meter_id: NotRequired[str]
    r"""meter_id is the optional unique identifier of the meter used for usage tracking"""
    period_end: NotRequired[str]
    r"""period_end is the optional end date of the period this line item covers"""
    period_start: NotRequired[str]
    r"""period_start is the optional start date of the period this line item covers"""
    plan_display_name: NotRequired[str]
    r"""plan_display_name is the optional human-readable name of the plan"""
    plan_id: NotRequired[str]
    r"""TODO: !REMOVE after migration
    plan_id is the optional unique identifier of the plan associated with this line item
    """
    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]
    r"""price_id is the optional unique identifier of the price associated with this line item"""
    price_type: NotRequired[str]
    r"""price_type indicates the type of pricing (fixed, usage, tiered, etc.)"""
    price_unit: NotRequired[str]
    r"""price_unit is the optional 3-digit ISO code of the price unit associated with this line item"""
    price_unit_amount: NotRequired[str]
    r"""price_unit_amount is the optional amount converted to the price unit currency"""


class DtoCreateInvoiceLineItemRequest(BaseModel):
    amount: str
    r"""amount is the monetary amount for this line item"""

    quantity: str
    r"""quantity is the quantity of units for this line item"""

    commitment_info: Optional[CommitmentInfo] = None

    display_name: Optional[str] = None
    r"""display_name is the optional human-readable name for this line item"""

    entity_id: Optional[str] = None
    r"""entity_id is the optional unique identifier of the entity associated with this line item"""

    entity_type: Optional[str] = None
    r"""entity_type is the optional type of the entity associated with this line item"""

    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
    r"""meter_display_name is the optional human-readable name of the meter"""

    meter_id: Optional[str] = None
    r"""meter_id is the optional unique identifier of the meter used for usage tracking"""

    period_end: Optional[str] = None
    r"""period_end is the optional end date of the period this line item covers"""

    period_start: Optional[str] = None
    r"""period_start is the optional start date of the period this line item covers"""

    plan_display_name: Optional[str] = None
    r"""plan_display_name is the optional human-readable name of the plan"""

    plan_id: Optional[str] = None
    r"""TODO: !REMOVE after migration
    plan_id is the optional unique identifier of the plan associated with this line item
    """

    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
    r"""price_id is the optional unique identifier of the price associated with this line item"""

    price_type: Optional[str] = None
    r"""price_type indicates the type of pricing (fixed, usage, tiered, etc.)"""

    price_unit: Optional[str] = None
    r"""price_unit is the optional 3-digit ISO code of the price unit associated with this line item"""

    price_unit_amount: Optional[str] = None
    r"""price_unit_amount is the optional amount converted to the price unit currency"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "commitment_info",
                "display_name",
                "entity_id",
                "entity_type",
                "invoice_level_discount",
                "line_item_discount",
                "metadata",
                "meter_display_name",
                "meter_id",
                "period_end",
                "period_start",
                "plan_display_name",
                "plan_id",
                "prepaid_credits_applied",
                "price_id",
                "price_type",
                "price_unit",
                "price_unit_amount",
            ]
        )
        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))

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

        return m
