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

from __future__ import annotations
from .offsetpagination import OffsetPagination, OffsetPaginationTypedDict
from .product import Product, ProductTypedDict
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, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class ListProductsRequestTypedDict(TypedDict):
    limit: NotRequired[int]
    r"""Number of products to return"""
    merchant_id: NotRequired[str]
    r"""Filter products by merchant organization ID"""
    offset: NotRequired[int]
    r"""Number of products to skip"""


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

    merchant_id: Annotated[
        Optional[str],
        pydantic.Field(alias="merchantId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter products by merchant organization ID"""

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

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


class ListProductsResponseTypedDict(TypedDict):
    r"""List of products"""

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


class ListProductsResponse(BaseModel):
    r"""List of products"""

    data: Optional[List[Product]] = 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)

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

        return m
