package com.gh.gamecenter.dsp.data

import com.gh.gamecenter.common.exposure.meta.MetaUtil
import com.gh.gamecenter.common.utils.toRequestBody
import com.gh.gamecenter.feature.entity.GameEntity
import com.gh.gamecenter.retrofit.RetrofitManager
import com.gh.gamecenter.retrofit.service.DspApiService
import io.reactivex.Single

class GameSubjectDSPRemoteDataSource(private val api: DspApiService = RetrofitManager.getInstance().dspApiService) {

    fun getDspGames(type: String, count: Int): Single<List<GameEntity>> {
        val meta = MetaUtil.getMeta()
        val request = mapOf(
            "device" to mapOf(
                "oaid" to (meta.oaid ?: ""),
                "brand" to (meta.manufacturer ?: ""),
                "model" to (meta.model ?: ""),
                "osv" to (MetaUtil.getAndroidVersion()),
            ),
            "count" to count,
            "scene" to 3,
            "busid" to "guanghuan1205"
        )
        return api.fetch(request.toRequestBody())
            .map {
                val gameEntityList = mutableListOf<GameEntity>()
                for (bidEntity in it.bidList) {
                    val gameEntity = bidEntity.toGameEntity()
                    gameEntityList.add(gameEntity)
                }
                gameEntityList
            }
    }

}