package com.gh.common.chain

import android.content.Context
import com.gh.gamecenter.feature.entity.GameEntity
import com.gh.vspace.VHelper

class ValidateVSpaceHandler : DownloadChainHandler() {

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

        if (asVGame) {
            VHelper.validateVSpaceBeforeAction(context,gameEntity.getUniquePackageName(), gameEntity) {
                closure.invoke()
            }
        } else {
            closure.invoke()
        }
    }
}