package com.bearya.kids.chapter

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.switchMap
import androidx.paging.PagedList
import com.bearya.data.entity.Chapter
import com.bearya.data.repository.ChapterRepository
import library.ext.toLiveData

class ChapterViewModel : ViewModel() {

    private val chapterRepository: ChapterRepository by lazy { ChapterRepository() }

    val gradeLevel : MutableLiveData<Int> by lazy { MutableLiveData<Int>() }

    val chapters: LiveData<PagedList<Chapter>>  = gradeLevel.switchMap {
        chapterRepository.findChaptersByGradeLevel(it).toLiveData()
    }
}