package com.idle.wall.ad

import com.tradplus.ads.open.interstitial.TPInterstitial

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

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

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

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

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

        }
        return count
    }
}