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

from __future__ import annotations
from .windowsize import WindowSize
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 DtoGetUsageByMeterRequestTypedDict(TypedDict):
    meter_id: str
    billing_anchor: NotRequired[str]
    r"""BillingAnchor enables custom monthly billing periods for meter usage aggregation.

    Usage guidelines:
    - Only effective when WindowSize = \"MONTH\" 
    - For other window sizes (DAY, HOUR, WEEK), this field is ignored
    - When nil, uses standard calendar months (1st to 1st)
    - When provided, creates custom monthly periods (e.g., 5th to 5th)

    Common use cases:
    - Subscription billing periods that don't align with calendar months
    - Customer-specific billing cycles (e.g., signed up on 15th)
    - Multi-tenant systems with different billing anchor dates

    Example: If BillingAnchor = \"2024-03-05T14:30:45Z\" and WindowSize = \"MONTH\":
    - March period: 2024-03-05 14:30:45 to 2024-04-05 14:30:45
    - April period: 2024-04-05 14:30:45 to 2024-05-05 14:30:45
    """
    bucket_size: NotRequired[WindowSize]
    customer_id: NotRequired[str]
    end_time: NotRequired[str]
    external_customer_id: NotRequired[str]
    filters: NotRequired[Dict[str, List[str]]]
    start_time: NotRequired[str]
    window_size: NotRequired[WindowSize]


class DtoGetUsageByMeterRequest(BaseModel):
    meter_id: str

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

    Usage guidelines:
    - Only effective when WindowSize = \"MONTH\" 
    - For other window sizes (DAY, HOUR, WEEK), this field is ignored
    - When nil, uses standard calendar months (1st to 1st)
    - When provided, creates custom monthly periods (e.g., 5th to 5th)

    Common use cases:
    - Subscription billing periods that don't align with calendar months
    - Customer-specific billing cycles (e.g., signed up on 15th)
    - Multi-tenant systems with different billing anchor dates

    Example: If BillingAnchor = \"2024-03-05T14:30:45Z\" and WindowSize = \"MONTH\":
    - March period: 2024-03-05 14:30:45 to 2024-04-05 14:30:45
    - April period: 2024-04-05 14:30:45 to 2024-05-05 14:30:45
    """

    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

    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",
                "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)

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

        return m
