import uuid
from typing import Generic, TypeVar

from pydantic import BaseModel, ConfigDict
from pydantic.alias_generators import to_camel

TEntity = TypeVar("TEntity", bound=BaseModel)


def create_uuid(prefix: str = None) -> str:
    if prefix:
        return f"{prefix}_{uuid.uuid4().hex}"
    else:
        return uuid.uuid4().hex


def create_shortuuid(prefix: str = None) -> str:
    short = uuid.uuid4().hex[:22]
    if prefix:
        return f"{prefix}_{short}"
    else:
        return short


class Paginated(BaseModel, Generic[TEntity]):
    items: list[TEntity]
    total: int
    page: int
    size: int

    model_config = ConfigDict(populate_by_name=True, alias_generator=to_camel)
