package com.rugvedsarika.toolbox

import android.content.Context
import android.content.SharedPreferences

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

    companion object {
        private const val KEY_FAVORITES = "favorite_tools"
        private const val KEY_THEME_MODE = "theme_mode"
        
        const val MODE_LIGHT = 1
        const val MODE_DARK = 2
        const val MODE_SYSTEM = 0
    }

    fun getThemeMode(): Int {
        return prefs.getInt(KEY_THEME_MODE, MODE_SYSTEM)
    }

    fun setThemeMode(mode: Int) {
        prefs.edit().putInt(KEY_THEME_MODE, mode).apply()
    }

    fun getFavoriteToolIds(): Set<String> {
        return prefs.getStringSet(KEY_FAVORITES, emptySet()) ?: emptySet()
    }

    fun toggleFavorite(toolId: String) {
        val favorites = getFavoriteToolIds().toMutableSet()
        if (favorites.contains(toolId)) {
            favorites.remove(toolId)
        } else {
            favorites.add(toolId)
        }
        prefs.edit().putStringSet(KEY_FAVORITES, favorites).apply()
    }

    fun isFavorite(toolId: String): Boolean {
        return getFavoriteToolIds().contains(toolId)
    }
}
