# coding: utf-8

"""
    Mixpeek API

    This is the Mixpeek API, providing access to various endpoints for data processing and retrieval.

    The version of the OpenAPI document: 1.3.0
    Contact: info@mixpeek.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from mixpeek.models.pagination_method import PaginationMethod
from typing import Optional, Set
from typing_extensions import Self

class KeysetPaginationParams(BaseModel):
    """
    Stateless keyset pagination relying on last seen sort key.  Best for: High-performance pagination, large result sets, stable sorting  How it works: - Uses actual field values as pagination markers - Database can use indexes efficiently (WHERE score < 0.73) - No offset calculation or server state - Requires deterministic sort order (e.g., score DESC, id ASC) - Most efficient pagination method  Requirements: - Results must be sorted consistently - Sort fields must be in the \"after\" marker - Example: sorted by (score DESC, id ASC) → after: {score: 0.73, id: \"doc_20\"}  Advantages: - No server-side state (truly stateless) - Consistent even with concurrent writes - Database can use indexes (fast for large datasets) - No offset performance degradation  Use when: - You have stable, deterministic sort fields - Working with large result sets (10k+ docs) - Maximum performance is critical - You need infinite scroll with best efficiency  Example flow: 1. Request: {\"method\": \"keyset\", \"limit\": 20, \"after\": null} 2. Response: {\"documents\": [...], \"next_cursor\": {\"score\": 0.85, \"id\": \"doc_20\"}} 3. Request: {\"method\": \"keyset\", \"limit\": 20, \"after\": {\"score\": 0.85, \"id\": \"doc_20\"}}
    """ # noqa: E501
    method: Optional[PaginationMethod] = Field(default=None, description="Constant identifying keyset pagination (REQUIRED).")
    limit: Optional[Annotated[int, Field(le=500, strict=True, ge=1)]] = Field(default=10, description="Maximum number of documents to return per page (REQUIRED). Default: 10.")
    after: Optional[Dict[str, Any]] = Field(default=None, description="Last seen keyset marker from previous response (OPTIONAL). Must include all sort fields. Example: {'score': 0.73, 'id': 'doc_20'}. null for first page, then use next_cursor from response")
    __properties: ClassVar[List[str]] = ["method", "limit", "after"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of KeysetPaginationParams from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of KeysetPaginationParams from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "method": obj.get("method"),
            "limit": obj.get("limit") if obj.get("limit") is not None else 10,
            "after": obj.get("after")
        })
        return _obj


