package com.lukouguoji.aerologic.ui.viewModel

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData
import com.alibaba.fastjson.JSONObject
import com.lukouguoji.module_base.http.user.UserNetwork
import kotlinx.coroutines.Dispatchers

class MineViewModel : ViewModel() {

    private val updatePwdParam = MutableLiveData<JSONObject>()

    val updatePwdLive = Transformations.switchMap(updatePwdParam) { param ->
        liveData(Dispatchers.IO) {
            try {
                val response = UserNetwork.updatePwd(param)
                emit(response)
            } catch (e: Exception) {
                Log.e("GoutCollectionViewModel", e.stackTraceToString())
            }
        }
    }

    fun updatePwd(
        oldPwd: String,
        newPwd: String
    ) {
        val param = JSONObject()
        param["oldPwd"] = oldPwd
        param["newPwd"] = newPwd
        updatePwdParam.value = param
    }

}