/*
 * Book's Story — free and open-source Material You eBook reader.
 * Copyright (C) 2024-2026 Acclorite
 * SPDX-License-Identifier: GPL-3.0-only
 */

package org.dueattendant149.bookshelf.domain.use_case.settings

import androidx.appcompat.app.AppCompatDelegate
import androidx.core.os.LocaleListCompat
import org.dueattendant149.bookshelf.core.language.Language
import org.dueattendant149.bookshelf.data.settings.SettingsManager
import javax.inject.Inject

class UpdateLanguageUseCase @Inject constructor(
    private val settings: SettingsManager
) {

    operator fun invoke(language: Language) {
        val appLocale = LocaleListCompat.forLanguageTags(language.locale.toLanguageTag())
        AppCompatDelegate.setApplicationLocales(appLocale)
        settings.language.update(language)
    }
}