package com.gh.gamecenter.personalhome.border

import android.annotation.SuppressLint
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import com.gh.gamecenter.entity.AvatarBorderCategoryEntity
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 AvatarBorderViewModel(application: Application) : AndroidViewModel(application) {

    val pendantCategories = MutableLiveData<ArrayList<AvatarBorderCategoryEntity>>()

    init {
        getPendantCategories()
    }

    @SuppressLint("CheckResult")
    fun getPendantCategories() {
        RetrofitManager.getInstance().api
            .pendantCategories
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : BiResponse<ArrayList<AvatarBorderCategoryEntity>>() {
                override fun onSuccess(data: ArrayList<AvatarBorderCategoryEntity>) {
                    pendantCategories.postValue(data)
                }

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