package com.rugvedsarika.voicereader.data

import android.content.Context
import android.content.SharedPreferences
import java.util.Locale

class PreferenceManager(context: Context) {
    private val prefs: SharedPreferences = context.getSharedPreferences("voice_reader_prefs", Context.MODE_PRIVATE)

    fun saveLanguage(locale: Locale) {
        prefs.edit().putString("selected_lang", locale.toLanguageTag()).apply()
    }

    fun getLanguage(): Locale {
        val tag = prefs.getString("selected_lang", Locale.getDefault().toLanguageTag())
        return Locale.forLanguageTag(tag ?: Locale.getDefault().toLanguageTag())
    }

    fun saveSpeed(speed: Float) {
        prefs.edit().putFloat("speech_rate", speed).apply()
    }

    fun getSpeed(): Float = prefs.getFloat("speech_rate", 1.0f)

    fun savePitch(pitch: Float) {
        prefs.edit().putFloat("pitch", pitch).apply()
    }

    fun getPitch(): Float = prefs.getFloat("pitch", 1.0f)

    fun saveTextSize(size: Float) {
        prefs.edit().putFloat("text_size", size).apply()
    }

    fun getTextSize(): Float = prefs.getFloat("text_size", 18f)

    fun setDummyDataGenerated(generated: Boolean) {
        prefs.edit().putBoolean("dummy_data_v2_generated", generated).apply()
    }

    fun isDummyDataGenerated(): Boolean = prefs.getBoolean("dummy_data_v2_generated", false)
}
