package com.jld.vod.repository

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

class GamePagingSource (private val articleApi: Apis,val mid:Long, val lid:Long,val terminal :String ) : PagingSource<Int, GameBean>() {

    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, GameBean> {
        val page = params.key ?: 0
        return try {
            val response = articleApi.findGameAll(mid,lid,terminal)
            if (response.code == 20000) {
               // LogUtils.logD("game"+response)
                LoadResult.Page(
                    data = response.data!!,
                    prevKey = null,
                    nextKey = null
                )
            } else {
                LoadResult.Error(Throwable(response.message))
            }
        } catch (e: Exception) {
            e.printStackTrace()
            LoadResult.Error(e)
        }
    }
}