"""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 DtoGetUsageAnalyticsRequestTypedDict(TypedDict):
    external_customer_id: str
    end_time: NotRequired[str]
    expand: NotRequired[List[str]]
    r"""allowed values: \"price\", \"meter\", \"feature\", \"subscription_line_item\",\"plan\",\"addon\" """
    feature_ids: NotRequired[List[str]]
    group_by: NotRequired[List[str]]
    r"""allowed values: \"source\", \"feature_id\", \"properties.<field_name>\" """
    property_filters: NotRequired[Dict[str, List[str]]]
    r"""Property filters to filter the events by the keys in `properties` field of the event"""
    sources: NotRequired[List[str]]
    start_time: NotRequired[str]
    window_size: NotRequired[WindowSize]


class DtoGetUsageAnalyticsRequest(BaseModel):
    external_customer_id: str

    end_time: Optional[str] = None

    expand: Optional[List[str]] = None
    r"""allowed values: \"price\", \"meter\", \"feature\", \"subscription_line_item\",\"plan\",\"addon\" """

    feature_ids: Optional[List[str]] = None

    group_by: Optional[List[str]] = None
    r"""allowed values: \"source\", \"feature_id\", \"properties.<field_name>\" """

    property_filters: Optional[Dict[str, List[str]]] = None
    r"""Property filters to filter the events by the keys in `properties` field of the event"""

    sources: Optional[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(
            [
                "end_time",
                "expand",
                "feature_ids",
                "group_by",
                "property_filters",
                "sources",
                "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
