package com.gh.gamecenter.qa.article.detail

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.gh.gamecenter.common.retrofit.Response
import com.gh.gamecenter.qa.entity.TopCommunityCategory
import com.gh.gamecenter.retrofit.RetrofitManager
import com.gh.gamecenter.retrofit.service.ApiService
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

/**
 * 论坛置顶类型
 */
class TopCommunityCategoryViewModel: ViewModel() {

    private val mApi: ApiService = RetrofitManager.getInstance().api

    val topCommunityCategoryList = MutableLiveData<List<TopCommunityCategory>>()

    val selectTopCommunityCategory = MutableLiveData<TopCommunityCategory?>(null)

    fun getTopCommunityCategory() {
        mApi.topCommunityCategory
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Response<List<TopCommunityCategory>>() {
                override fun onResponse(response: List<TopCommunityCategory>?) {
                    response?.let {
                        topCommunityCategoryList.value = it
                    }
                }
            })
    }

    fun submitTopCommunityCategory(category: TopCommunityCategory) {
        selectTopCommunityCategory.value = category
    }

}