namespace StellaOps.Feedser.Source.Common.Cursors;

/// <summary>
/// Provides helpers for computing pagination start indices for sources that expose total result counts.
/// </summary>
public static class PaginationPlanner
{
    /// <summary>
    /// Enumerates additional page start indices given the total result count returned by the source.
    /// The first page (at <paramref name="firstPageStartIndex"/>) is assumed to be already fetched.
    /// </summary>
    public static IEnumerable<int> EnumerateAdditionalPages(int totalResults, int resultsPerPage, int firstPageStartIndex = 0)
    {
        if (totalResults <= 0 || resultsPerPage <= 0)
        {
            yield break;
        }

        if (firstPageStartIndex < 0)
        {
            firstPageStartIndex = 0;
        }

        for (var start = firstPageStartIndex + resultsPerPage; start < totalResults; start += resultsPerPage)
        {
            yield return start;
        }
    }
}
