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

from __future__ import annotations
from .groupinvoicesummary import GroupInvoiceSummary, GroupInvoiceSummaryTypedDict
from .invoicesummary import InvoiceSummary, InvoiceSummaryTypedDict
from .paymentsummary import PaymentSummary, PaymentSummaryTypedDict
from .revenuetrendbucket import RevenueTrendBucket, RevenueTrendBucketTypedDict
from paygentic_sdk.types import BaseModel, UNSET_SENTINEL
from paygentic_sdk.utils import validate_const
import pydantic
from pydantic import model_serializer
from pydantic.functional_validators import AfterValidator
from typing import List, Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class RevenueSummaryResponseTypedDict(TypedDict):
    net_revenue: str
    r"""Net collected revenue in dollars (paid invoices + completed payments)"""
    invoices: InvoiceSummaryTypedDict
    payments: PaymentSummaryTypedDict
    trend: List[RevenueTrendBucketTypedDict]
    r"""Time-bucketed revenue trend data"""
    object: Literal["revenue_summary"]
    r"""Object type identifier"""
    group_breakdown: NotRequired[List[GroupInvoiceSummaryTypedDict]]
    r"""Invoice breakdown by group dimension (only present when groupBy is specified)"""


class RevenueSummaryResponse(BaseModel):
    net_revenue: Annotated[str, pydantic.Field(alias="netRevenue")]
    r"""Net collected revenue in dollars (paid invoices + completed payments)"""

    invoices: InvoiceSummary

    payments: PaymentSummary

    trend: List[RevenueTrendBucket]
    r"""Time-bucketed revenue trend data"""

    object: Annotated[
        Annotated[
            Literal["revenue_summary"],
            AfterValidator(validate_const("revenue_summary")),
        ],
        pydantic.Field(alias="object"),
    ] = "revenue_summary"
    r"""Object type identifier"""

    group_breakdown: Annotated[
        Optional[List[GroupInvoiceSummary]], pydantic.Field(alias="groupBreakdown")
    ] = None
    r"""Invoice breakdown by group dimension (only present when groupBy is specified)"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["groupBreakdown"])
        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


try:
    RevenueSummaryResponse.model_rebuild()
except NameError:
    pass
