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.feature.entity.GameEntity

class DownloadDialogHelperHandler : DownloadChainHandler() {

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