package de.sebse.fuplanner2.ui.details_announcements

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.Announcement
import de.sebse.fuplanner2.database.AppDatabase

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

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