// Copyright (C) 2026 Jason M. Schwefel. All Rights Reserved.
package com.coldboreballisticsllc.scopedope.ui.screens.onboarding

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import com.coldboreballisticsllc.scopedope.data.prefs.AppPreferences
import javax.inject.Inject

@HiltViewModel
class OnboardingViewModel @Inject constructor(
    private val prefs: AppPreferences,
) : ViewModel() {

    // null = reading from disk, false = show onboarding, true = already complete
    val onboardingComplete: StateFlow<Boolean?> = prefs.onboardingComplete
        .map { it as Boolean? }
        .stateIn(viewModelScope, SharingStarted.Eagerly, null)

    fun markComplete() {
        viewModelScope.launch { prefs.setOnboardingComplete() }
    }

    fun resetOnboarding() {
        viewModelScope.launch { prefs.resetOnboarding() }
    }
}
