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

from __future__ import annotations
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 DtoGetEventsRequestTypedDict(TypedDict):
    end_time: NotRequired[str]
    r"""End time of the events to be fetched in ISO 8601 format
    Defaults to now if not provided
    """
    event_id: NotRequired[str]
    r"""Event ID is the idempotency key for the event"""
    event_name: NotRequired[str]
    r"""Event name / Unique identifier for the event in your system"""
    external_customer_id: NotRequired[str]
    r"""Customer ID in your system that was sent with the event"""
    iter_first_key: NotRequired[str]
    r"""First key to iterate over the events"""
    iter_last_key: NotRequired[str]
    r"""Last key to iterate over the events"""
    offset: NotRequired[int]
    r"""Offset to fetch the events and is set to 0 by default"""
    order: NotRequired[str]
    r"""Order by condition. Allowed values (case sensitive): asc, desc (default: desc)"""
    page_size: NotRequired[int]
    r"""Page size to fetch the events and is set to 50 by default"""
    property_filters: NotRequired[Dict[str, List[str]]]
    r"""Property filters to filter the events by the keys in `properties` field of the event"""
    sort: NotRequired[str]
    r"""Sort by the field. Allowed values (case sensitive): timestamp, event_name (default: timestamp)"""
    source: NotRequired[str]
    r"""Source to filter the events by the source"""
    start_time: NotRequired[str]
    r"""Start time of the events to be fetched in ISO 8601 format
    Defaults to last 7 days from now if not provided
    """


class DtoGetEventsRequest(BaseModel):
    end_time: Optional[str] = None
    r"""End time of the events to be fetched in ISO 8601 format
    Defaults to now if not provided
    """

    event_id: Optional[str] = None
    r"""Event ID is the idempotency key for the event"""

    event_name: Optional[str] = None
    r"""Event name / Unique identifier for the event in your system"""

    external_customer_id: Optional[str] = None
    r"""Customer ID in your system that was sent with the event"""

    iter_first_key: Optional[str] = None
    r"""First key to iterate over the events"""

    iter_last_key: Optional[str] = None
    r"""Last key to iterate over the events"""

    offset: Optional[int] = None
    r"""Offset to fetch the events and is set to 0 by default"""

    order: Optional[str] = None
    r"""Order by condition. Allowed values (case sensitive): asc, desc (default: desc)"""

    page_size: Optional[int] = None
    r"""Page size to fetch the events and is set to 50 by default"""

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

    sort: Optional[str] = None
    r"""Sort by the field. Allowed values (case sensitive): timestamp, event_name (default: timestamp)"""

    source: Optional[str] = None
    r"""Source to filter the events by the source"""

    start_time: Optional[str] = None
    r"""Start time of the events to be fetched in ISO 8601 format
    Defaults to last 7 days from now if not provided
    """

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "end_time",
                "event_id",
                "event_name",
                "external_customer_id",
                "iter_first_key",
                "iter_last_key",
                "offset",
                "order",
                "page_size",
                "property_filters",
                "sort",
                "source",
                "start_time",
            ]
        )
        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
