package com.gh.gamecenter.gamedetail.fuli.kaifu

import androidx.lifecycle.*
import com.gh.gamecenter.entity.CalendarEntity

class ServersCalendarDetailViewModel(
    source: LiveData<List<CalendarEntity>>,
    val year: Int,
    val month: Int,
    val day: Int,
    val showRemind: Boolean
) : ViewModel() {

    var calendarEntityLiveData = Transformations.switchMap(source) {
        Transformations.distinctUntilChanged(
            MutableLiveData(
                it.find { calendar ->
                    calendar.year == year
                            && calendar.month == month
                            && calendar.day == day
                }
            )
        )
    }

    class Factory(
        private val source: LiveData<List<CalendarEntity>>,
        private val year: Int,
        private val month: Int,
        private val day: Int,
        private val showRemind: Boolean
    ) : ViewModelProvider.NewInstanceFactory() {
        override fun <T : ViewModel> create(modelClass: Class<T>): T {
            return ServersCalendarDetailViewModel(source, year, month, day, showRemind) as T
        }
    }

}