package de.sebse.fuplanner2.ui.tools.viewmodels

import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.livedata.observeAsState
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import de.sebse.fuplanner2.database.Announcement
import de.sebse.fuplanner2.database.AppDatabase


class AnnouncementViewModelFactory(private val announcementId: Long): ViewModelProvider.NewInstanceFactory() {
    override fun <T : ViewModel> create(modelClass: Class<T>): T = AnnouncementViewModel(announcementId) as T
}

class AnnouncementViewModel(private val announcementId: Long) : ViewModel() {
    private val announcement: LiveData<Announcement> =
        AppDatabase.getInstance().announcementDao().getAnnouncementById2(announcementId)

    @Composable
    fun observeAsState(): State<Announcement?> {
        return announcement.observeAsState()
    }
}
