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

from __future__ import annotations
from .grouptrendentry import GroupTrendEntry, GroupTrendEntryTypedDict
from datetime import datetime
from paygentic_sdk.types import BaseModel, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class RevenueTrendBucketTypedDict(TypedDict):
    timestamp: datetime
    r"""Start time of this bucket"""
    issued_invoices: str
    r"""Total amount of all invoices issued in this bucket (all statuses, by issuedAt)"""
    written_off_invoices: str
    r"""Amount of written-off invoices in dollars for this bucket (by writtenOffAt)"""
    completed_payments: str
    r"""Revenue from completed payments in dollars for this bucket"""
    group_breakdown: NotRequired[List[GroupTrendEntryTypedDict]]
    r"""Per-group trend entries (only present when groupBy is specified)"""


class RevenueTrendBucket(BaseModel):
    timestamp: datetime
    r"""Start time of this bucket"""

    issued_invoices: Annotated[str, pydantic.Field(alias="issuedInvoices")]
    r"""Total amount of all invoices issued in this bucket (all statuses, by issuedAt)"""

    written_off_invoices: Annotated[str, pydantic.Field(alias="writtenOffInvoices")]
    r"""Amount of written-off invoices in dollars for this bucket (by writtenOffAt)"""

    completed_payments: Annotated[str, pydantic.Field(alias="completedPayments")]
    r"""Revenue from completed payments in dollars for this bucket"""

    group_breakdown: Annotated[
        Optional[List[GroupTrendEntry]], pydantic.Field(alias="groupBreakdown")
    ] = None
    r"""Per-group trend entries (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:
    RevenueTrendBucket.model_rebuild()
except NameError:
    pass
