package com.gh.gamecenter.gamedetail.accelerator.chain

import android.content.Context
import com.gh.common.dialog.AccelerateExpirationDialogFragment
import com.gh.gamecenter.R
import com.gh.gamecenter.common.constant.Constants
import com.gh.gamecenter.common.utils.toResString
import com.gh.gamecenter.core.utils.SPUtils
import com.gh.gamecenter.gamedetail.accelerator.dialog.AcceleratorDialogFragment
import com.gh.gamecenter.gamedetail.accelerator.dialog.AcceleratorDialogFragment.Companion.SPEED_ENABLE_VIP
import com.halo.assistant.accelerator.repository.AcceleratorDataHolder

class AcceleratorVipInterceptor : AcceleratorValidator.Interceptor {

    override fun intercept(
        context: Context,
        chain: AcceleratorValidator.Chain,
        listener: AcceleratorValidator.ValidateListener?
    ) {
        val request = chain.request
        val vip = AcceleratorDataHolder.instance.vipEntity
        if (vip?.vipStatus == true || vip?.isNewUser == true) {
            chain.proceed(context, request, listener)
        } else {
            val reminder = AccelerateExpirationDialogFragment.ExpirationReminder.TimeRunsOut(request.sourceEntrance)
            AccelerateExpirationDialogFragment.checkDialogShown(context, reminder) {
                if (!it) {
                    val game = request.game
                    AcceleratorDialogFragment.show(
                        SPEED_ENABLE_VIP,
                        game.getUniquePackageName() ?: "",
                        game.id,
                        game.name ?: "",
                        request.sourceEntrance,
                        context
                    )
                }
            }
        }
    }
}