package com.gh.gamecenter.gamecollection.tag

import android.annotation.SuppressLint
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import com.gh.gamecenter.entity.GameCollectionTagEntity
import com.gh.gamecenter.common.retrofit.BiResponse
import com.gh.gamecenter.retrofit.RetrofitManager
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

class GameCollectionTagViewModel(application: Application) : AndroidViewModel(application) {

    var tagListLiveData = MutableLiveData<ArrayList<GameCollectionTagEntity>>()
    private val mApi = RetrofitManager.getInstance().api

    init {
        getGameCollectionTagList()
    }

    @SuppressLint("CheckResult")
    fun getGameCollectionTagList() {
        mApi.gameCollectionTagList
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : BiResponse<ArrayList<GameCollectionTagEntity>>() {
                override fun onSuccess(data: ArrayList<GameCollectionTagEntity>) {
                    tagListLiveData.postValue(data)
                }
            })
    }
}