package dev.meloda.fast.common.paging

fun canPaginate(pageSize: Int, loadedCount: Int): Boolean = loadedCount == pageSize

fun isPaginationExhausted(
    pageSize: Int,
    loadedCount: Int,
    hasExistingItems: Boolean
): Boolean = loadedCount != pageSize && hasExistingItems

fun <T> mergePage(
    existing: List<T>,
    page: List<T>,
    offset: Int
): List<T> = if (offset == 0) page else existing + page

data class LoadingFlags(
    val isLoading: Boolean,
    val isPaginating: Boolean
)

fun loadingFlags(offset: Int, isLoading: Boolean): LoadingFlags = LoadingFlags(
    isLoading = offset == 0 && isLoading,
    isPaginating = offset > 0 && isLoading
)
