package rowedto.jockeyedto.sheetedto.strangeedto.pyramidedto.particlesedto.cherryedto.ranchedto.gunedto

import android.content.Context
import android.util.Log
import com.applovin.sdk.AppLovinMediationProvider
import com.applovin.sdk.AppLovinSdk
import com.applovin.sdk.AppLovinSdkInitializationConfiguration
import rowedto.jockeyedto.sheetedto.raceedto.pavementedto.Dishedto
import rowedto.jockeyedto.sheetedto.raceedto.pavementedto.Slantedto
import rowedto.jockeyedto.sheetedto.strangeedto.pyramidedto.particlesedto.Scandaledto.isAdInit
import java.util.concurrent.Executors

object Establishededto {

    private val TAG = "AdMaxInit"

    var maxInitAction: (() -> Unit)? = null

    fun Context.initAdMax() {
        Log.d(TAG, "initAdMax")

        // If you want to test your own AppLovin SDK key, change the value here and update the package name in the build.gradle
//        val YOUR_SDK_KEY = "05TMDQ5tZabpXQ45_UTbmEGNUtVAzSTzT6KmWQc5_CuWdzccS4DCITZoL3yIWUG3bbq60QC_d4WF28tUC4gVTF"
        val YOUR_SDK_KEY = "GGPreND6SRmCt1zJgn5faiLGD8c2PVGPLgPpSg7cHanVTud1DhtuI9MmteTqlEviaJ57WnxW68kQDaATJ5z3cW"

        val executor = Executors.newSingleThreadExecutor();
        executor.execute {

            val initConfigBuilder = AppLovinSdkInitializationConfiguration.builder(YOUR_SDK_KEY, this)
            initConfigBuilder.mediationProvider = AppLovinMediationProvider.MAX


            // Enable test mode by default for the current device. Cannot be run on the main thread.
//            AppLovinSdk.getInstance( this ).showMediationDebugger()
//            val currentGaid = AdvertisingIdClient.getAdvertisingIdInfo(this).id
//            if (currentGaid != null) {
//                initConfigBuilder.testDeviceAdvertisingIds = Collections.singletonList(currentGaid)
//            }

            // Initialize the AppLovin SDK
            val sdk = AppLovinSdk.getInstance(this)
            sdk.initialize(initConfigBuilder.build()) {
                Dishedto.logDebug(TAG, "max init")
                isAdInit.set(true)
                maxInitAction?.invoke()
                maxInitAction = null
                Slantedto.event("MaxInit", "MaxInit")
            }

            executor.shutdown()
        }
    }
}