package com.zj365.mime.vm

import androidx.lifecycle.MutableLiveData
import com.tamsiree.rxkit.RxTool
import com.xty.base.vm.BaseVm
import com.xty.common.util.CommonToastUtils
import com.zj365.mime.R
import com.xty.network.model.RespBody

class ChangePwdVm : BaseVm() {

    val codeLive by lazy { MutableLiveData<RespBody<String>>() }
    val changePwd by lazy { MutableLiveData<RespBody<String>>() }

    fun sendCodeForget(phone: String) {
        startHttp {
            var code = apiInterface().sendCodeForget(phone)
            code.getCodeStatus(codeLive, nowData)
        }
    }

    fun changePsw(phone: String, code: String, pwd: String) {
        if (phone.isEmpty()) {
            CommonToastUtils.showToast(R.string.please_input_phone)
            return
        }
        if (code.isEmpty()) {
            CommonToastUtils.showToast(R.string.please_input_code)
            return
        }


        if (pwd.isEmpty()) {
            CommonToastUtils.showToast(R.string.please_input_new_pwd)
            return
        }
        if (pwd.length < 6) {
            CommonToastUtils.showToast(R.string.please_input_ok_password)
            return
        }
        startHttp {
            var code = apiInterface().changePsw(phone, code, RxTool.Md5(pwd))
            code.getCodeStatus(changePwd, nowData)
        }
    }
}