package com.gamedog.vididin.feature.home.repository


import com.gamedog.vididin.beans.ResYoutubeChannel
import com.gamedog.vididin.beans.ResYoutubePlayList
import com.gamedog.vididin.beans.YoutubeVideo
import com.gamedog.vididin.core.data.repository.refreshloadmore.PageKeyedMemoryRefreshLoadMoreRepository
import com.gamedog.vididin.main.fragments.home.YoutubeDataSource
import com.gamedog.vididin.main.fragments.home.YoutubeRepository
import javax.inject.Inject


class DefaultYoutubeRepository @Inject constructor(
    private val network: YoutubeDataSource,
) : PageKeyedMemoryRefreshLoadMoreRepository<YoutubeVideo>(), YoutubeRepository {

    var mRespPlayList : ResYoutubePlayList? = null

    override suspend fun getVideoList(
        page: Int,
        size: Int
    ): ResYoutubePlayList {
        return network.getVideoList(mRespPlayList?.nextPageToken)
    }

    override suspend fun getChannelList(
        page: Int,
        size: Int
    ): ResYoutubeChannel {
        return network.getChannels()
    }

    override suspend fun getListDataByKey(
        key: Int,
        pageSize: Int
    ): List<YoutubeVideo>? {
        mRespPlayList = getVideoList(key, pageSize)
        return mRespPlayList?.items
    }


}
