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

from __future__ import annotations
from .offsetpagination import OffsetPagination, OffsetPaginationTypedDict
from .usageevent import UsageEvent, UsageEventTypedDict
from datetime import datetime
from paygentic_sdk.types import BaseModel, UNSET_SENTINEL
from paygentic_sdk.utils import FieldMetadata, QueryParamMetadata
import pydantic
from pydantic import model_serializer
from typing import List, Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class ListUsageEventsRequestTypedDict(TypedDict):
    end_time: datetime
    r"""ISO 8601 date-time string filtering events up to this timestamp. Sample values: '2024-01-31T23:59:59Z', '2024-02-28T12:00:00Z'"""
    start_time: datetime
    r"""ISO 8601 date-time string filtering events from this timestamp onward. Sample values: '2024-01-15T00:00:00Z', '2024-02-01T10:30:00Z'"""
    consumer_id: NotRequired[str]
    r"""Filter by consumer ID. This is only available if the caller is member of the consumer organization."""
    customer_id: NotRequired[str]
    r"""Filter by customer ID. This is only available if the caller is member of the merchant organization owning this customer."""
    limit: NotRequired[int]
    r"""Number of usage events to return"""
    merchant_id: NotRequired[str]
    r"""Filter by merchant ID. This is only available if the caller is member of the merchant organization."""
    offset: NotRequired[int]
    r"""Number of usage events to skip"""
    subscription_id: NotRequired[str]
    r"""Filter by subscription ID. This is only available if the caller is member of the consumer or merchant organization owning this subscription."""


class ListUsageEventsRequest(BaseModel):
    end_time: Annotated[
        datetime,
        pydantic.Field(alias="endTime"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ]
    r"""ISO 8601 date-time string filtering events up to this timestamp. Sample values: '2024-01-31T23:59:59Z', '2024-02-28T12:00:00Z'"""

    start_time: Annotated[
        datetime,
        pydantic.Field(alias="startTime"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ]
    r"""ISO 8601 date-time string filtering events from this timestamp onward. Sample values: '2024-01-15T00:00:00Z', '2024-02-01T10:30:00Z'"""

    consumer_id: Annotated[
        Optional[str],
        pydantic.Field(alias="consumerId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter by consumer ID. This is only available if the caller is member of the consumer organization."""

    customer_id: Annotated[
        Optional[str],
        pydantic.Field(alias="customerId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter by customer ID. This is only available if the caller is member of the merchant organization owning this customer."""

    limit: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 10
    r"""Number of usage events to return"""

    merchant_id: Annotated[
        Optional[str],
        pydantic.Field(alias="merchantId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter by merchant ID. This is only available if the caller is member of the merchant organization."""

    offset: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 0
    r"""Number of usage events to skip"""

    subscription_id: Annotated[
        Optional[str],
        pydantic.Field(alias="subscriptionId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter by subscription ID. This is only available if the caller is member of the consumer or merchant organization owning this subscription."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "consumerId",
                "customerId",
                "limit",
                "merchantId",
                "offset",
                "subscriptionId",
            ]
        )
        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


ListUsageEventsObject = Literal["list",]


class ListUsageEventsResponseTypedDict(TypedDict):
    r"""List of usage events"""

    object: NotRequired[ListUsageEventsObject]
    data: NotRequired[List[UsageEventTypedDict]]
    pagination: NotRequired[OffsetPaginationTypedDict]
    r"""Offset-based pagination response."""


class ListUsageEventsResponse(BaseModel):
    r"""List of usage events"""

    object: Optional[ListUsageEventsObject] = None

    data: Optional[List[UsageEvent]] = None

    pagination: Optional[OffsetPagination] = None
    r"""Offset-based pagination response."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["object", "data", "pagination"])
        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
