from typing import Optional, List

from pydantic import Field
from src.models import DefultBase


class CommonParams(DefultBase):
    # This ensures no extra query params are allowed
    current_user: Optional[str] = Field(None, alias="currentUser", max_length=50)
    page: int = Field(1, gt=0, lt=2147483647)
    items_per_page: int = Field(5, gt=0, le=50, multiple_of=5, alias="itemsPerPage")
    query_str: Optional[str] = Field(None, alias="q", max_length=100)
    filter_spec: Optional[str] = Field(None, alias="filter", max_length=500)
    sort_by: List[str] = Field(default_factory=list, alias="sortBy[]")
    descending: List[bool] = Field(default_factory=list, alias="descending[]")
    exclude: List[str] = Field(default_factory=list, alias="exclude[]")
    all_params: int = Field(0, alias="all")

    # Property to mirror your original return dict's bool conversion
    @property
    def is_all(self) -> bool:
        return bool(self.all_params)