package com.base.appzxhy.business.pangle

import android.util.Log
import com.base.appzxhy.GlobalConfig
import com.base.appzxhy.business.ads.AdsShowCallBack
import com.base.appzxhy.utils.LogEx
import com.bytedance.sdk.openadsdk.api.interstitial.PAGInterstitialAd
import com.bytedance.sdk.openadsdk.api.interstitial.PAGInterstitialAdLoadListener
import com.bytedance.sdk.openadsdk.api.interstitial.PAGInterstitialRequest

class PangleInterMgr {

    private val TAG = "PangleInterMgr"
    private var interstitialAd: PAGInterstitialAd? = null
    private var showCallBack: AdsShowCallBack? = null

    fun load(callback: ((flag: Boolean) -> Unit)? = null) {
        PAGInterstitialAd.loadAd(
            GlobalConfig.ID_PANGLE_INTER,
            PAGInterstitialRequest(),
            object : PAGInterstitialAdLoadListener {
                override fun onError(code: Int, message: String?) {
                    LogEx.logDebug(TAG, "loadAd onError code=$code message=$message")
                    callback?.invoke(false)
                }

                override fun onAdLoaded(pagInterstitialAd: PAGInterstitialAd?) {
                    LogEx.logDebug(TAG, "onAdLoaded")
                    interstitialAd = pagInterstitialAd
                    callback?.invoke(true)
                }
            })
    }
}