package com.fabledsword.minstrel.theme

/**
 * User-selectable theme override. SYSTEM defers to
 * `isSystemInDarkTheme()`; LIGHT and DARK pin the app to that mode
 * regardless of the device setting.
 *
 * Stored as the wire string in `AuthSessionEntity.themeMode`. Null
 * persistence value means "never set" which we treat as SYSTEM.
 */
enum class ThemeMode {
    SYSTEM, LIGHT, DARK;

    /** Stable string identifier used for persistence. */
    val wire: String get() = name.lowercase()

    /**
     * Maps to MinstrelTheme's `darkOverride: Boolean?` parameter:
     *   - SYSTEM → null (let isSystemInDarkTheme decide)
     *   - LIGHT  → false
     *   - DARK   → true
     */
    fun toDarkOverride(): Boolean? = when (this) {
        SYSTEM -> null
        LIGHT -> false
        DARK -> true
    }

    companion object {
        fun fromWire(wire: String?): ThemeMode = when (wire) {
            "light" -> LIGHT
            "dark" -> DARK
            else -> SYSTEM
        }
    }
}
