package com.bearya.kids.section

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.Section
import com.bearya.data.repository.SectionRepository
import library.ext.setData
import library.ext.toLiveData

class SectionViewModel : ViewModel() {

    private val repository: SectionRepository by lazy { SectionRepository() }

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

    val sections :LiveData<PagedList<Section>> = chapterId.switchMap {
        repository.findSectionByChapterId(it).toLiveData()
    }

    var sectionDirFileSize : Int = 0

    val playIndex: MutableLiveData<Int> by lazy { MutableLiveData<Int>().apply { setData(0) } }
}