package com.pixelized.headache.ui.page.summary.yearly

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.pixelized.headache.repository.event.EventRepository
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 javax.inject.Inject


@HiltViewModel
class YearSummaryViewModel @Inject constructor(
    eventRepository: EventRepository,
    summaryFactory: YearSummaryFactory,
) : ViewModel() {

    val events: StateFlow<List<YearUio>> = eventRepository
        .eventsMapFlow()
        .map(summaryFactory::convertToUio)
        .stateIn(
            scope = viewModelScope,
            started = SharingStarted.Lazily,
            initialValue = emptyList(),
        )
}