package com.gh.gamecenter.pkg

import android.annotation.SuppressLint
import android.content.Context
import com.alibaba.android.arouter.facade.annotation.Route
import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.common.entity.PkgConfigEntity
import com.gh.gamecenter.core.provider.IPkgProvider
import com.gh.gamecenter.pkg.retrofit.RetrofitManager
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

@Route(path = RouteConsts.provider.pkg, name = "PKG 暴露服务")
class PkgProviderImpl : IPkgProvider<PkgConfigEntity> {

    @SuppressLint("CheckResult")
    override fun requestPkgConfig(configId: String, onConfigReceived: (config: PkgConfigEntity) -> Unit) {
        RetrofitManager.getInstance().api.getPkgConfig(configId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe({
                onConfigReceived.invoke(it)
            }, {
                it.printStackTrace()
            })
    }

    override fun init(context: Context?) {
        // Do nothing
    }

}