package app.closer

import android.app.Application
import app.closer.core.firebase.FirebaseInitializer
import app.closer.data.repository.ActivityProvider
import app.closer.domain.security.DeviceIntegrityChecker
import app.closer.notifications.NotificationChannelSetup
import com.google.crypto.tink.aead.AeadConfig
import com.google.crypto.tink.hybrid.HybridConfig
import dagger.hilt.android.HiltAndroidApp
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltAndroidApp
class CloserApp : Application() {

    @Inject lateinit var firebaseInitializer: FirebaseInitializer
    @Inject lateinit var deviceIntegrityChecker: DeviceIntegrityChecker

    private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)

    override fun onCreate() {
        super.onCreate()
        AeadConfig.register()
        HybridConfig.register()
        ActivityProvider.register(this)
        NotificationChannelSetup.createChannels(applicationContext)
        firebaseInitializer.initialize()
        appScope.launch { deviceIntegrityChecker.runCheck() }
    }
}
