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

from __future__ import annotations
from .plan import Plan, PlanTypedDict
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 ListAvailablePlansRequestTypedDict(TypedDict):
    customer_id: str
    r"""The customer to check subscriptions for. The merchant is derived from the customer record."""
    product_id: NotRequired[str]
    r"""Optional filter by product ID"""
    search: NotRequired[str]
    r"""Optional search text to filter plan names (case-insensitive)"""
    limit: NotRequired[int]
    r"""Number of plans to return"""
    offset: NotRequired[int]
    r"""Number of plans to skip"""


class ListAvailablePlansRequest(BaseModel):
    customer_id: Annotated[
        str,
        pydantic.Field(alias="customerId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ]
    r"""The customer to check subscriptions for. The merchant is derived from the customer record."""

    product_id: Annotated[
        Optional[str],
        pydantic.Field(alias="productId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Optional filter by product ID"""

    search: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Optional search text to filter plan names (case-insensitive)"""

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

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["productId", "search", "limit", "offset"])
        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 ListAvailablePlansPaginationTypedDict(TypedDict):
    limit: NotRequired[int]
    offset: NotRequired[int]
    total: NotRequired[int]


class ListAvailablePlansPagination(BaseModel):
    limit: Optional[int] = None

    offset: Optional[int] = None

    total: Optional[int] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["limit", "offset", "total"])
        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 ListAvailablePlansResponseTypedDict(TypedDict):
    r"""List of available plans"""

    data: NotRequired[List[PlanTypedDict]]
    pagination: NotRequired[ListAvailablePlansPaginationTypedDict]


class ListAvailablePlansResponse(BaseModel):
    r"""List of available plans"""

    data: Optional[List[Plan]] = None

    pagination: Optional[ListAvailablePlansPagination] = None

    @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
