package com.github.nullptroma.wallenc.app.locale

import android.content.Context
import com.github.nullptroma.wallenc.ui.locale.AppLanguage
import com.github.nullptroma.wallenc.ui.locale.AppLocaleController
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class AppLocaleControllerImpl @Inject constructor(
    @param:ApplicationContext private val context: Context,
) : AppLocaleController {

    override val language: Flow<AppLanguage> = AppLocaleStorage.languageFlow(context)

    override suspend fun setLanguage(language: AppLanguage) {
        AppLocaleStorage.persistLanguage(context, language)
    }

    override suspend fun applyStoredLocale() {
        AppLocaleStorage.applyStored(context)
    }
}
