package com.gh.common.chain

import android.content.Context
import com.gh.common.util.DownloadDialogHelper
import com.gh.gamecenter.common.utils.safelyGetInRelease
import com.gh.gamecenter.core.utils.EmptyCallback
import com.gh.gamecenter.entity.GameEntity

class DownloadDialogHelperHandler : ChainHandler() {

    override fun handleRequest(context: Context, gameEntity: GameEntity) {
        val apk = gameEntity.getApk().safelyGetInRelease(0) ?: return
        DownloadDialogHelper.findAvailableDialogAndShow(context, gameEntity, apk, object : EmptyCallback {
            override fun onCallback() {
                if (hasNext()) {
                    getNext()?.handleRequest(context, gameEntity)
                } else {
                    processEndCallback?.invoke(null)
                }
            }
        })
    }
}