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

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.pixelized.headache.repository.event.EventRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import javax.inject.Inject

@HiltViewModel
class MonthSummaryViewModel @Inject constructor(
    eventRepository: EventRepository,
    eventItemFactory: MonthSummaryFactory,
) : ViewModel() {

    @OptIn(ExperimentalCoroutinesApi::class)
    val events = eventRepository.eventsMapFlow()
        .map { events ->
            eventItemFactory.convertToItemUio(events = events)
        }.stateIn(
            scope = viewModelScope,
            started = SharingStarted.Lazily,
            initialValue = emptyMap(),
        )
}