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

import android.content.Context
import com.gh.common.dialog.AcceleratorPermissionGuideDialogFragment
import com.gh.gamecenter.common.constant.Constants
import com.gh.gamecenter.core.utils.SPUtils

class AcceleratorPermissionGuideInterceptor : AcceleratorValidator.Interceptor {
    override fun intercept(
        context: Context,
        chain: AcceleratorValidator.Chain,
        listener: AcceleratorValidator.ValidateListener?
    ) {
        val hasShow = SPUtils.getBoolean(Constants.SP_ACCELERATOR_PERMISSION_GUIDE_SHOW)
        val request = chain.request
        if (hasShow) {
            chain.proceed(context, request, listener)
        } else {
            AcceleratorPermissionGuideDialogFragment.show(context) {
                if (chain.isValidContext(context)) {
                    chain.proceed(context, request, listener)
                }
            }
        }
    }
}