package com.gogame.minesweeper.ad

import com.thinkup.interstitial.api.TUInterstitial


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

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

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

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

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

        }
        return count
    }
}