package com.cheng.blzb.ui.fragment.mine.settings

import androidx.lifecycle.MutableLiveData
import com.example.base.extensions.toast
import com.example.base.utils.L
import com.example.base.viewmodel.BaseViewModel
import com.cheng.blzb.net.ApiFactory

class SettingsViewModel : BaseViewModel() {
    val logoutLiveData = MutableLiveData<Any>()
    val destroyLiveData = MutableLiveData<Any>()

    fun logout() {
        showDialog()
        launchOnUiTryCatch({
            val response = ApiFactory.apiService.logout()
            if (response.status) {
                logoutLiveData.postValue(Any())
            } else {
                toast(response.message, true)
            }
            dismissDialog()
        }, {
            dismissDialog()
            setError(it)
            L.d(it)
        })
    }

    fun userDestroy() {
        showDialog()
        launchOnUiTryCatch({
            val response = ApiFactory.apiService.userDestroy()
            if (response.status) {
                destroyLiveData.postValue(response.data)
            } else {
                toast(response.message, true)
            }
            dismissDialog()
        }, {
            dismissDialog()
            setError(it)
            L.d(it)
        })
    }
}