package com.gh.gamecenter.minigame

import com.gh.gamecenter.dsp.data.GameSubjectDSPRemoteDataSource
import com.gh.gamecenter.entity.SearchSubjectEntity
import com.gh.gamecenter.feature.entity.GameEntity
import com.gh.gamecenter.minigame.wechat.WGameSubjectCPMRemoteDataSource
import com.gh.gamecenter.retrofit.RetrofitManager
import com.gh.gamecenter.retrofit.service.ApiService
import com.gh.gamecenter.search.ISearchGameResultRepository
import io.reactivex.Observable
import io.reactivex.Single

class MiniGameSearchResultRepository(
    private val api: ApiService = RetrofitManager.getInstance().newApi,
    private val mWGameSubjectCPMDataSource: WGameSubjectCPMRemoteDataSource = WGameSubjectCPMRemoteDataSource(),
    private val mGameSubjectDSPDataSource: GameSubjectDSPRemoteDataSource = GameSubjectDSPRemoteDataSource(RetrofitManager.getInstance().dspApiService)
) : ISearchGameResultRepository {

    override fun getSearchGame(
        key: String?,
        page: Int
    ): Observable<List<GameEntity>> {
        return api.getSearchMiniGameList(key, page, 20)
    }

    override fun getSearchMiniGameCPM(key: String?): Observable<List<GameEntity>> {
        return Observable.just(emptyList())
    }

    override fun getSearchSubject(key: String?, page: Int): Observable<List<SearchSubjectEntity>> {
        return Observable.just(emptyList())
    }

    override fun getWGameCPMGameList(size: Int): Single<MutableList<GameEntity>> {
        return mWGameSubjectCPMDataSource.getUserRecommendCPMList(pageSize = size)
    }

    override fun getDspGameList(
        columnType: String,
        showDownload: Boolean,
        size: Int,
    ): Single<List<GameEntity>> {
        return mGameSubjectDSPDataSource.getDspGames(columnType, size)
    }
}