package com.gh.common.chain

import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import com.gh.common.dialog.PackageCheckDialogFragment
import com.gh.gamecenter.feature.entity.GameEntity

class PackageCheckHandler : DownloadChainHandler() {

    override fun handleRequest(context: Context, gameEntity: GameEntity, asVGame: Boolean) {
        fun nextOrProcessEnd() {
            if (hasNext()) {
                getNext()?.handleRequest(context, gameEntity, asVGame)
            } else {
                processEndCallback?.invoke(asVGame, null)
            }
        }

        if (gameEntity.canSpeed) {
            nextOrProcessEnd()
        } else {
            PackageCheckDialogFragment.show((context as AppCompatActivity), gameEntity) {
                nextOrProcessEnd()
            }
        }

    }
}