package com.colorful.keyboard.theme.ad

import com.anythink.interstitial.api.ATInterstitial

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

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

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

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

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

        }
        return count
    }
}