package com.example.livingai.pages.onboarding

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.livingai.domain.model.SettingsData
import com.example.livingai.domain.usecases.AppDataUseCases
import kotlinx.coroutines.launch

class OnBoardingViewModel(
    private val appDataUseCases: AppDataUseCases
): ViewModel() {
    fun onEvent(event: OnBoardingEvents) {
        when(event) {
            is OnBoardingEvents.SaveAppEntry -> {
                saveAppEntry()
            }
            is OnBoardingEvents.SaveLanguage -> {
                saveLanguage(event.language)
            }
        }
    }

    private fun saveAppEntry() {
        viewModelScope.launch {
            appDataUseCases.saveAppEntry()
        }
    }

    private fun saveLanguage(language: String) {
        viewModelScope.launch {
            // Preserving default for other settings or we could fetch existing if needed
            // For onboarding, assuming defaults for others is fine.
            appDataUseCases.saveSettings(SettingsData(language = language, isAutoCaptureOn = false))
        }
    }
}