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

from __future__ import annotations
from enum import Enum
from outpost_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
import pydantic
from pydantic import model_serializer
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class Dir(str, Enum):
    r"""Sort direction."""

    ASC = "asc"
    DESC = "desc"


class SeekPaginationTypedDict(TypedDict):
    r"""Cursor-based pagination metadata for list responses."""

    order_by: NotRequired[str]
    r"""The field being sorted on."""
    dir: NotRequired[Dir]
    r"""Sort direction."""
    limit: NotRequired[int]
    r"""Page size limit."""
    next_cursor: NotRequired[Nullable[str]]
    r"""Cursor for the next page of results. Null if no more results."""
    prev_cursor: NotRequired[Nullable[str]]
    r"""Cursor for the previous page of results. Null if on first page."""


class SeekPagination(BaseModel):
    r"""Cursor-based pagination metadata for list responses."""

    order_by: Optional[str] = None
    r"""The field being sorted on."""

    dir: Optional[Dir] = None
    r"""Sort direction."""

    limit: Optional[int] = None
    r"""Page size limit."""

    next_cursor: Annotated[OptionalNullable[str], pydantic.Field(alias="next")] = UNSET
    r"""Cursor for the next page of results. Null if no more results."""

    prev_cursor: Annotated[OptionalNullable[str], pydantic.Field(alias="prev")] = UNSET
    r"""Cursor for the previous page of results. Null if on first page."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["order_by", "dir", "limit", "next_cursor", "prev_cursor"]
        )
        nullable_fields = set(["next_cursor", "prev_cursor"])
        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))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

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

        return m


try:
    SeekPagination.model_rebuild()
except NameError:
    pass
