package com.gh.gamecenter.gamecollection.publish

import android.annotation.SuppressLint
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import com.gh.gamecenter.entity.ActivityLabelEntity
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 GameCollectionActivityLabelViewModel(application: Application) :
    AndroidViewModel(application) {
    val activityTags = MutableLiveData<ArrayList<ActivityLabelEntity>?>()

    init {
        getActivityTags()
    }

    @SuppressLint("CheckResult")
    private fun getActivityTags() {
        RetrofitManager.getInstance().api
            .gameCollectionActivityLabelList
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : BiResponse<ArrayList<ActivityLabelEntity>>() {
                override fun onSuccess(data: ArrayList<ActivityLabelEntity>) {
                    activityTags.postValue(data)
                }

                override fun onFailure(exception: Exception) {
                    super.onFailure(exception)
                    activityTags.postValue(null)
                }
            })
    }
}