package com.gallery.free.wallpaper.environment.ad

import com.unity3d.mediation.interstitial.LevelPlayInterstitialAd


class InstAdCacheManager {
    private val mAdCacheDict: MutableMap<String, LevelPlayInterstitialAd> = mutableMapOf()

    companion object {
        val instance: InstAdCacheManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            InstAdCacheManager()
        }
    }

    fun setAdCache(place: String, adCache: LevelPlayInterstitialAd) {
        mAdCacheDict[place] = adCache
    }

    fun getAdCache(place: String): LevelPlayInterstitialAd? {
        return mAdCacheDict[place]
    }

    fun getLoadedInstCount(): Int {
        var count = 0
        try {
            mAdCacheDict.forEach  { (key, value) ->
                if (value.isAdReady) {
                    count += 1
                }
            }
        } catch (_: Exception) {

        }
        return count
    }
}