package com.tt.honeyDue.storage

import platform.Foundation.NSUserDefaults

/**
 * iOS implementation of theme storage using NSUserDefaults.
 */
actual class ThemeStorageManager {
    private val defaults = NSUserDefaults.standardUserDefaults

    actual fun saveThemeId(themeId: String) {
        defaults.setObject(themeId, forKey = KEY_THEME_ID)
        defaults.synchronize()
    }

    actual fun getThemeId(): String? {
        return defaults.stringForKey(KEY_THEME_ID)
    }

    actual fun clearThemeId() {
        defaults.removeObjectForKey(KEY_THEME_ID)
        defaults.synchronize()
    }

    actual fun saveUseDynamicColor(enabled: Boolean) {
        defaults.setBool(enabled, forKey = KEY_USE_DYNAMIC_COLOR)
        defaults.synchronize()
    }

    actual fun getUseDynamicColor(): Boolean {
        // iOS has no Material You — always false. Still read/write so stored
        // state survives a platform reinstall scenario and cross-platform parity
        // APIs stay symmetric.
        return defaults.boolForKey(KEY_USE_DYNAMIC_COLOR)
    }

    companion object {
        private const val KEY_THEME_ID = "theme_id"
        private const val KEY_USE_DYNAMIC_COLOR = "use_dynamic_color"

        private val instance by lazy { ThemeStorageManager() }

        fun getInstance(): ThemeStorageManager = instance
    }
}
