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

from __future__ import annotations
import pydantic
from pydantic import model_serializer
from squadcast.types import BaseModel, UNSET_SENTINEL
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class CommonV4PageInfoTypedDict(TypedDict):
    page_size: int
    has_next: bool
    has_prev: bool
    next_cursor: NotRequired[str]
    prev_cursor: NotRequired[str]


class CommonV4PageInfo(BaseModel):
    page_size: Annotated[int, pydantic.Field(alias="pageSize")]

    has_next: Annotated[bool, pydantic.Field(alias="hasNext")]

    has_prev: Annotated[bool, pydantic.Field(alias="hasPrev")]

    next_cursor: Annotated[Optional[str], pydantic.Field(alias="nextCursor")] = None

    prev_cursor: Annotated[Optional[str], pydantic.Field(alias="prevCursor")] = None

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


try:
    CommonV4PageInfo.model_rebuild()
except NameError:
    pass
