package de.sebse.fuplanner2.ui.details_events

import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList
import de.sebse.fuplanner2.database.AppDatabase
import de.sebse.fuplanner2.database.Event


class EventsViewModelFactory(private val courseId: Long): ViewModelProvider.NewInstanceFactory() {
    override fun <T : ViewModel> create(modelClass: Class<T>): T = EventsViewModel(courseId) as T
}

class EventsViewModel(courseId: Long) : ViewModel() {
    private val factory = AppDatabase.getInstance().eventDao().getAll1(courseId)
    val events: LiveData<PagedList<Event>> = LivePagedListBuilder(factory, 50).build()
}