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

from __future__ import annotations
from .offsetpagination import OffsetPagination, OffsetPaginationTypedDict
from .sourceevent import SourceEvent, SourceEventTypedDict
from paygentic_sdk.types import BaseModel, UNSET_SENTINEL
from paygentic_sdk.utils import FieldMetadata, PathParamMetadata, QueryParamMetadata
import pydantic
from pydantic import model_serializer
from typing import List, Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


ListSourceEventsStatus = Literal[
    "pending",
    "processed",
    "failed",
    "rejected",
]
r"""Filter events by status"""


class ListSourceEventsRequestTypedDict(TypedDict):
    id: str
    customer_id: NotRequired[str]
    r"""Filter events by customer ID"""
    limit: NotRequired[int]
    offset: NotRequired[int]
    status: NotRequired[ListSourceEventsStatus]
    r"""Filter events by status"""
    subscription_id: NotRequired[str]
    r"""Filter events by subscription ID"""


class ListSourceEventsRequest(BaseModel):
    id: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]

    customer_id: Annotated[
        Optional[str],
        pydantic.Field(alias="customerId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter events by customer ID"""

    limit: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 10

    offset: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 0

    status: Annotated[
        Optional[ListSourceEventsStatus],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter events by status"""

    subscription_id: Annotated[
        Optional[str],
        pydantic.Field(alias="subscriptionId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter events by subscription ID"""

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


class ListSourceEventsResponseTypedDict(TypedDict):
    r"""List of source events"""

    data: NotRequired[List[SourceEventTypedDict]]
    pagination: NotRequired[OffsetPaginationTypedDict]
    r"""Offset-based pagination response."""


class ListSourceEventsResponse(BaseModel):
    r"""List of source events"""

    data: Optional[List[SourceEvent]] = None

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

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