<?php

/**
 * Safe pagination parameters — prevents negative LIMIT offsets.
 *
 * @return array{page: int, perPage: int, offset: int}
 */
function pagination_params(?int $page = null, int $perPage = 25): array
{
    $page    = max(1, (int) ($page ?? 1));
    $perPage = max(1, $perPage);
    $offset  = ($page - 1) * $perPage;

    return [
        'page'    => $page,
        'perPage' => $perPage,
        'offset'  => $offset,
    ];
}
