package com.jld.vod.repository

import androidx.paging.PagingSource
import com.jld.vod.interfaces.remote.Apis
import com.jld.vod.model.bean.BrowserBean
import com.jld.vod.model.bean.CategoryFatherAllBean
import com.jld.vod.model.bean.CategorySonAllBean
import com.jld.vod.model.bean.GameBean
import com.jld.vod.utils.LogUtils

class CategorySonAllPagingSource (private val articleApi: Apis, val cid:Long, val lid:Long) : PagingSource<Int, CategorySonAllBean>() {

    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, CategorySonAllBean> {
        val page = params.key ?: 0
        return try {
            val response = articleApi.findCategorySonAllByCid(cid,lid)
            if (response.code == 20000) {
                LoadResult.Page(
                    data = response.data!!,
                    prevKey = null,
                    nextKey = null
                )
            } else {
                LoadResult.Error(Throwable(response.message))
            }
        } catch (e: Exception) {
            e.printStackTrace()
            LoadResult.Error(e)
        }
    }
}