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.model.bean.MovieByMidBean
import com.jld.vod.model.bean.MusicByMidBean

class MoviePagingSource (private val articleApi: Apis, val cid:Long, val mid:Long, val lid:Long ) : PagingSource<Int, MovieByMidBean>() {

    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, MovieByMidBean> {
        val page = params.key ?: 0
        return try {
            val response = articleApi.findMovieByCid(cid,mid,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)
        }
    }
}