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

from __future__ import annotations
from .aggregationtype import AggregationType
from .windowsize import WindowSize
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, List, Optional
from typing_extensions import NotRequired, TypedDict


class DtoGetUsageRequestTypedDict(TypedDict):
    aggregation_type: AggregationType
    event_name: str
    billing_anchor: NotRequired[str]
    r"""BillingAnchor enables custom monthly billing periods for usage aggregation.

    When to use:
    - WindowSize = \"MONTH\" AND you need custom monthly periods (not calendar months)
    - Subscription billing that doesn't align with calendar months
    - Example: Customer signed up on 15th, so billing periods are 15th to 15th

    When NOT to use:
    - WindowSize != \"MONTH\" (ignored for DAY, HOUR, WEEK, etc.)
    - Standard calendar-based billing (1st to 1st of each month)

    Example values:
    - \"2024-03-05T14:30:45.123456789Z\" (5th of each month at 2:30:45 PM)
    - \"2024-01-15T00:00:00Z\" (15th of each month at midnight)
    - \"2024-02-29T12:00:00Z\" (29th of each month at noon - handles leap years)
    """
    bucket_size: NotRequired[WindowSize]
    customer_id: NotRequired[str]
    end_time: NotRequired[str]
    external_customer_id: NotRequired[str]
    filters: NotRequired[Dict[str, List[str]]]
    group_by_property: NotRequired[str]
    r"""GroupByProperty is the property name in event.properties to group by before aggregating.
    When set, aggregation is applied per unique value of this property within each bucket,
    then the per-group results are summed to produce the bucket total.
    """
    multiplier: NotRequired[str]
    property_name: NotRequired[str]
    r"""will be empty/ignored in case of COUNT"""
    start_time: NotRequired[str]
    window_size: NotRequired[WindowSize]


class DtoGetUsageRequest(BaseModel):
    aggregation_type: AggregationType

    event_name: str

    billing_anchor: Optional[str] = None
    r"""BillingAnchor enables custom monthly billing periods for usage aggregation.

    When to use:
    - WindowSize = \"MONTH\" AND you need custom monthly periods (not calendar months)
    - Subscription billing that doesn't align with calendar months
    - Example: Customer signed up on 15th, so billing periods are 15th to 15th

    When NOT to use:
    - WindowSize != \"MONTH\" (ignored for DAY, HOUR, WEEK, etc.)
    - Standard calendar-based billing (1st to 1st of each month)

    Example values:
    - \"2024-03-05T14:30:45.123456789Z\" (5th of each month at 2:30:45 PM)
    - \"2024-01-15T00:00:00Z\" (15th of each month at midnight)
    - \"2024-02-29T12:00:00Z\" (29th of each month at noon - handles leap years)
    """

    bucket_size: Optional[WindowSize] = None

    customer_id: Optional[str] = None

    end_time: Optional[str] = None

    external_customer_id: Optional[str] = None

    filters: Optional[Dict[str, List[str]]] = None

    group_by_property: Optional[str] = None
    r"""GroupByProperty is the property name in event.properties to group by before aggregating.
    When set, aggregation is applied per unique value of this property within each bucket,
    then the per-group results are summed to produce the bucket total.
    """

    multiplier: Optional[str] = None

    property_name: Optional[str] = None
    r"""will be empty/ignored in case of COUNT"""

    start_time: Optional[str] = None

    window_size: Optional[WindowSize] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "billing_anchor",
                "bucket_size",
                "customer_id",
                "end_time",
                "external_customer_id",
                "filters",
                "group_by_property",
                "multiplier",
                "property_name",
                "start_time",
                "window_size",
            ]
        )
        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
