from typing import Generic, Optional, Sequence, TypeVar

from fastapi import Query
from pydantic import BaseModel

T = TypeVar("T")


class PaginatedResult(BaseModel, Generic[T]):
    model_config = {"arbitrary_types_allowed": True}

    items: Sequence[T]
    page: int
    page_size: int
    total: int


class PaginationQuery(BaseModel):
    q: Optional[str] = Query(None, description="Search query")
    page: int = Query(1, ge=1, description="Page number")
    page_size: int = Query(10, ge=1, le=100, description="Items per page")
