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

from __future__ import annotations
from .offsetpagination import OffsetPagination, OffsetPaginationTypedDict
from .subscription import Subscription, SubscriptionTypedDict
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


ListSubscriptionsStatus = Literal[
    "active",
    "terminated",
]


class ListSubscriptionsRequestTypedDict(TypedDict):
    consumer_id: NotRequired[str]
    customer_id: NotRequired[str]
    limit: NotRequired[str]
    r"""Number of subscriptions to return"""
    merchant_id: NotRequired[str]
    offset: NotRequired[str]
    r"""Number of subscriptions to skip"""
    status: NotRequired[ListSubscriptionsStatus]


class ListSubscriptionsRequest(BaseModel):
    consumer_id: Annotated[
        Optional[str],
        pydantic.Field(alias="consumerId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

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

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

    merchant_id: Annotated[
        Optional[str],
        pydantic.Field(alias="merchantId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

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

    status: Annotated[
        Optional[ListSubscriptionsStatus],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["consumerId", "customerId", "limit", "merchantId", "offset", "status"]
        )
        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 ListSubscriptionsResponseTypedDict(TypedDict):
    r"""List of subscriptions"""

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


class ListSubscriptionsResponse(BaseModel):
    r"""List of subscriptions"""

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