package com.syaroful.agrilinkvocpro.plant_disease_detection_feature.presentation.history

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.syaroful.agrilinkvocpro.plant_disease_detection_feature.data.local.entity.PlantDiagnosisEntity
import com.syaroful.agrilinkvocpro.plant_disease_detection_feature.data.repository.PlantDiagnosisLocalRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.stateIn

class HistoryViewModel(
    private val repository: PlantDiagnosisLocalRepository
) : ViewModel() {

    val diagnoses = repository.getAllDiagnosis().stateIn(
        viewModelScope,
        SharingStarted.WhileSubscribed(5000),
        emptyList()
    )

    fun getDiagnosisById(id: Int): Flow<PlantDiagnosisEntity?> {
        return repository.getDiagnosisById(id)
    }
}
