package com.keyboard.craft

import android.app.Application
import android.content.Intent
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.applovin.sdk.AppLovinMediationProvider
import com.applovin.sdk.AppLovinSdk
import com.applovin.sdk.AppLovinSdkConfiguration
import com.applovin.sdk.AppLovinSdkInitializationConfiguration
import com.keyboard.craft.db.DatabaseManager


class CraftApp : Application() {
    companion object {
        lateinit var app: CraftApp
        const val TAG = "CraftApp"

        lateinit var databaseManager: DatabaseManager
            private set

    }

    override fun onCreate() {
        super.onCreate()
        app = this
        databaseManager = DatabaseManager.getInstance(this)
        initMAxSDk()

    }

    var initSDkOK: Boolean = false
    var initAction: String = "ACTION_INIT"
    private val SDK_KEY = "VVN64VW3_CeQrIZ9sSUMQAWAS4XI14L2etylkN_E2IkJpZrsF6Xt26aMuwBGOboUiFvkTVJ28EbPW53NL_6SPT"
    private fun initMAxSDk() {
        val initConfig = AppLovinSdkInitializationConfiguration.builder(SDK_KEY, this)
            .setMediationProvider(AppLovinMediationProvider.MAX)
            .build()
        AppLovinSdk.getInstance(this)
            .initialize(initConfig, object : AppLovinSdk.SdkInitializationListener {
                override fun onSdkInitialized(appLovinSdkConfiguration: AppLovinSdkConfiguration?) {
                    initSDkOK = true
                    LocalBroadcastManager.getInstance(this@CraftApp).sendBroadcast(Intent(initAction));
                }
            })

    }
}