package com.gh.common.chain

import android.content.Context
import com.gh.gamecenter.common.utils.PermissionHelper
import com.gh.gamecenter.feature.entity.GameEntity

class CheckStoragePermissionHandler : DownloadChainHandler() {

    override fun handleRequest(context: Context, gameEntity: GameEntity, asVGame: Boolean) {
        PermissionHelper.checkStoragePermissionBeforeAction(
            context,
            gameEntity.id,
            gameEntity.name ?: "",
            gameEntity.categoryChinese,
            gameEntity.getApk().firstOrNull()?.format,
        ) {
            if (hasNext()) {
                getNext()?.handleRequest(context, gameEntity, asVGame)
            } else {
                processEndCallback?.invoke(asVGame, null)
            }
        }
    }
}