package com.gh.gamecenter.personalhome.home

import android.app.Application
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.gh.common.constant.Config
import com.gh.gamecenter.common.baselist.ListViewModel
import com.gh.gamecenter.entity.MyVideoEntity
import com.gh.gamecenter.retrofit.RetrofitManager
import io.reactivex.Observable

class UserVideoHistoryViewModel(application: Application, var userId: String) :
    ListViewModel<MyVideoEntity, MyVideoEntity>(application) {

    override fun provideDataObservable(page: Int): Observable<MutableList<MyVideoEntity>> {
        return RetrofitManager.getInstance().api.getUserVideo(userId, page, Config.VIDEO_PAGE_SIZE)
    }

    override fun mergeResultLiveData() {
        mResultLiveData.addSource(mListLiveData) { mResultLiveData.postValue(it) }
    }

    class Factory(
        private val mApplication: Application,
        private val mUserId: String
    ) : ViewModelProvider.NewInstanceFactory() {
        override fun <T : ViewModel> create(modelClass: Class<T>): T {
            return UserVideoHistoryViewModel(mApplication, mUserId) as T
        }
    }

}