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

from __future__ import annotations
from .customer import Customer, CustomerTypedDict
from .offsetpagination import OffsetPagination, OffsetPaginationTypedDict
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 ListCustomersRequestTypedDict(TypedDict):
    organization_id: str
    r"""ID of the merchant organization to filter customers by"""
    limit: NotRequired[int]
    r"""Number of customers to return"""
    offset: NotRequired[int]
    r"""Number of customers to skip"""
    name: NotRequired[str]
    r"""Filter customers by consumer name (case-insensitive substring match). Minimum 3 characters required for efficient index usage."""
    email: NotRequired[str]
    r"""Filter customers by billing email (case-insensitive substring match). Minimum 3 characters required for efficient index usage. Accepts partial values — e.g. a domain (\"acme.com\") or local part (\"billing\")."""


class ListCustomersRequest(BaseModel):
    organization_id: Annotated[
        str,
        pydantic.Field(alias="organizationId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ]
    r"""ID of the merchant organization to filter customers by"""

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

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

    name: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter customers by consumer name (case-insensitive substring match). Minimum 3 characters required for efficient index usage."""

    email: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter customers by billing email (case-insensitive substring match). Minimum 3 characters required for efficient index usage. Accepts partial values — e.g. a domain (\"acme.com\") or local part (\"billing\")."""

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


ListCustomersObject = Literal["list",]


class ListCustomersResponseTypedDict(TypedDict):
    r"""List of customers retrieved successfully"""

    object: ListCustomersObject
    data: List[CustomerTypedDict]
    pagination: OffsetPaginationTypedDict
    r"""Offset-based pagination response."""


class ListCustomersResponse(BaseModel):
    r"""List of customers retrieved successfully"""

    object: ListCustomersObject

    data: List[Customer]

    pagination: OffsetPagination
    r"""Offset-based pagination response."""
