import math

from typing import TypedDict

PAGINATION_LIMIT = 50


class TDPagination(TypedDict):
    total_count: int
    limit: int
    total_pages: int
    current_page: int
    offset: int


def create_pagination(total_count: int, current_page: int | None = None) -> TDPagination:
    limit = PAGINATION_LIMIT
    total_pages = math.ceil(total_count / limit)
    current = current_page or total_pages
    offset = (current - 1) * limit

    pagination = TDPagination(
        total_count=total_count, limit=limit, total_pages=total_pages, current_page=current, offset=offset
    )

    return pagination
