package com.aiosman.riderpro

import kotlin.math.min

class MockDataContainer<T>(
    val success: Boolean,
    val data: T?
) {

}

class MockListContainer<T>(
    val total: Int,
    val page: Int,
    val pageSize: Int,
    val list: List<T>
) {

}

abstract class MockDataSource<T> {
    var list = mutableListOf<T>()
    suspend fun fetchData(page: Int, pageSize: Int): MockDataContainer<MockListContainer<T>> {
        // over page return empty
        if (page * pageSize > list.size) {
            return MockDataContainer(false, MockListContainer(0, page, pageSize, emptyList()))
        }
        val backData = list.subList((page - 1) * pageSize, min(page * pageSize, list.size))
        return MockDataContainer(true, MockListContainer(list.size, page, pageSize, backData))
    }
}