package com.halo.assistant.fragment.user

import android.annotation.SuppressLint
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import com.gh.gamecenter.common.retrofit.BiResponse
import com.gh.gamecenter.common.utils.singleToMain
import com.gh.gamecenter.retrofit.RetrofitManager
import com.google.gson.JsonObject

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

    var certificationSwitch = MutableLiveData<Boolean>()

    init {
        getCertificationSwitch()
    }

    @SuppressLint("CheckResult")
    fun getCertificationSwitch() {
        RetrofitManager.getInstance().api
            .certificationSwitch
            .compose(singleToMain())
            .subscribe(object : BiResponse<JsonObject>() {
                override fun onSuccess(data: JsonObject) {
                    certificationSwitch.postValue(data["authentication_display_switch"].asString == "on")
                }

                override fun onFailure(exception: Exception) {
                    super.onFailure(exception)
                    certificationSwitch.postValue(false)
                }

            })
    }
}