package eu.gaudian.translator

import android.app.Application
import dagger.hilt.android.HiltAndroidApp
import eu.gaudian.translator.model.repository.ApiRepository
import eu.gaudian.translator.model.repository.LanguageRepository
import timber.log.Timber

@HiltAndroidApp
class MyApplication : Application() {

    private var _languageRepository: LanguageRepository? = null
    private var _apiRepository: ApiRepository? = null

    val languageRepository: LanguageRepository
        get() = _languageRepository ?: synchronized(this) {
            _languageRepository ?: LanguageRepository(this).also {
                _languageRepository = it
            }
        }

    val apiRepository: ApiRepository
        get() = _apiRepository ?: synchronized(this) {
            _apiRepository ?: ApiRepository(this).also {
                _apiRepository = it
            }
        }

    override fun onCreate() {
        super.onCreate()

        if (BuildConfig.DEBUG) {
            Timber.plant(Timber.DebugTree())
        }
    }
}