package com.laseroptek.raman.ui.screens.home.dcd

import androidx.compose.runtime.toMutableStateList
import androidx.lifecycle.ViewModel
import com.laseroptek.raman.const.SprayDcdList
import com.laseroptek.raman.data.model.serial.SprayDcd
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import timber.log.Timber
import javax.inject.Inject

@HiltViewModel
class DcdViewModel @Inject constructor(
) : ViewModel() {

    // copied from mainViewModel
    // sprayDcdList - Spreay DCD Option List (6 Fixed Size List)
    var sprayDcdList = SprayDcdList.toMutableStateList()
    fun setSprayDcdList(list: List<SprayDcd>) {
        sprayDcdList = list.map{ it.copy() }.toMutableStateList()
    }
    fun setSprayDcd(idx: Int, item: SprayDcd) {
        sprayDcdList[idx] = item.copy()
    }

    // copied from mainViewModel
    // selectedSprayDcdIndex - 메인 화면 DCD { Spray | Delay }
    // - DcdSettingPopup에서 선택한 sprayDcdList index
    private val _selectedSprayDcdIndex: MutableStateFlow<Int> = MutableStateFlow(0)
    val selectedSprayDcdIndex = _selectedSprayDcdIndex.asStateFlow()
    fun setSelectedSprayDcdIndex(i: Int) { _selectedSprayDcdIndex.value = i }

    // selectedSprayDcdIndex - 메인 화면 DCD { Spray | Delay }
    // - DcdSettingPopup에서 선택한 sprayDcdList index
    private val _selectedOptionIndex: MutableStateFlow<Int> = MutableStateFlow(0)
    val selectedOptionIndex = _selectedOptionIndex.asStateFlow()
    fun setSelectedOptionIndex(i: Int) { _selectedOptionIndex.value = i }

    init {
        Timber.d("DcdViewModel init")
    }
}