package app.closer.domain.repository

import app.closer.core.notifications.QuietHours
import kotlinx.coroutines.flow.Flow

enum class ThemeMode {
    DEVICE,
    LIGHT,
    DARK;

    companion object {
        fun fromStorageValue(value: String?): ThemeMode =
            entries.firstOrNull { it.name == value } ?: DEVICE
    }
}

data class AppSettings(
    val dailyReminderEnabled: Boolean = true,
    val partnerAnsweredEnabled: Boolean = true,
    val chatMessageEnabled: Boolean = true,
    val streakReminderEnabled: Boolean = false,
    val quietHoursEnabled: Boolean = false,
    val quietHours: QuietHours = QuietHours(),
    val onboardingComplete: Boolean = false,
    val themeMode: ThemeMode = ThemeMode.DEVICE,
    val outcomeReminderEnabled: Boolean = true,
    val outcomeBaselineShownAt: Long = 0L,
    val outcomeLastPromptedDay: String = "",
    val biometricLoginEnabled: Boolean = false,
    /** Highest streak milestone (7/30/100/365) already celebrated, so each fires once. */
    val lastCelebratedStreakMilestone: Int = 0
)

interface SettingsRepository {
    val settings: Flow<AppSettings>
    suspend fun setDailyReminder(enabled: Boolean)
    suspend fun setPartnerAnswered(enabled: Boolean)
    suspend fun setChatMessage(enabled: Boolean)
    suspend fun setStreakReminder(enabled: Boolean)
    suspend fun setQuietHours(enabled: Boolean)
    suspend fun setQuietHours(quietHours: QuietHours)
    suspend fun setOnboardingComplete(complete: Boolean)
    suspend fun setThemeMode(mode: ThemeMode)
    suspend fun setOutcomeReminderEnabled(enabled: Boolean)
    suspend fun markOutcomeBaselineShown()
    suspend fun setOutcomeLastPromptedDay(dayKey: String)
    suspend fun setBiometricLogin(enabled: Boolean)
    suspend fun setLastCelebratedStreakMilestone(milestone: Int)
}
