package com.tt.honeyDue.storage

/**
 * Cross-platform theme storage for persisting theme selection.
 * Uses platform-specific implementations (SharedPreferences on Android, UserDefaults on iOS).
 */
object ThemeStorage {
    private var manager: ThemeStorageManager? = null

    fun initialize(themeManager: ThemeStorageManager) {
        manager = themeManager
    }

    fun saveThemeId(themeId: String) {
        manager?.saveThemeId(themeId)
    }

    fun getThemeId(): String? {
        return manager?.getThemeId()
    }

    fun clearThemeId() {
        manager?.clearThemeId()
    }

    /**
     * Persist whether the user has opted into dynamic color (Material You) on
     * Android 12+. Defaults to `false` when unset so existing users keep the
     * custom theme they chose.
     */
    fun saveUseDynamicColor(enabled: Boolean) {
        manager?.saveUseDynamicColor(enabled)
    }

    fun getUseDynamicColor(): Boolean {
        return manager?.getUseDynamicColor() ?: false
    }
}

/**
 * Platform-specific theme storage interface.
 * Each platform implements this using their native storage mechanisms.
 */
expect class ThemeStorageManager {
    fun saveThemeId(themeId: String)
    fun getThemeId(): String?
    fun clearThemeId()
    fun saveUseDynamicColor(enabled: Boolean)
    fun getUseDynamicColor(): Boolean
}
