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

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.combine
import kotlinx.coroutines.flow.stateIn
import javax.inject.Inject

@HiltViewModel
class ReportViewModel @Inject constructor(
    eventRepository: EventRepository,
    reportFactory: ReportFactory,
) : ViewModel() {

    val events: StateFlow<List<ReportBoxUio>> = combine(
        eventRepository.maxPillAmountPerMonthFlow(),
        eventRepository.eventsMapFlow(),
        reportFactory::convertToUio
    ).stateIn(
        scope = viewModelScope,
        started = SharingStarted.Lazily,
        initialValue = emptyList(),
    )
}