package com.zj365.mime.vm

import androidx.lifecycle.MutableLiveData
import com.xty.base.vm.BaseVm
import com.xty.network.model.ImageUploadBean
import com.xty.network.model.NotAccepted
import com.xty.network.model.RespBody
import okhttp3.MultipartBody
import org.json.JSONObject
import java.io.File

class MyInfoVm : BaseVm() {

    val imageLive by lazy { MutableLiveData<RespBody<ImageUploadBean>>() }
    val changeSuccess by lazy{MutableLiveData<RespBody<NotAccepted>>()}
    val changeMedicSuccess by lazy{MutableLiveData<RespBody<NotAccepted>>()}

    fun changeImage(path: String) {
        if (path.isEmpty()) {
            return
        }
        var f=File(path)
        var rb = MultipartBody.Part.createFormData("file", f.name, retrofits.getMultiPartFileRb(f))
        startHttp {
            var body=apiInterface().uploadImage(rb)
            body.getCodeStatus(imageLive,nowData)
        }
    }

    fun changeInfo(key:String,value:String){
        startHttp {
            var json=JSONObject()
            json.put(key,value)

            var body=apiInterface().setUpdateUser(retrofits.getRequestBody(json.toString()))
            body.getCodeStatus(changeSuccess,nowData)
        }
    }

    fun changeMedic(ids:String,medicName:String){
        startHttp {
            var json=JSONObject()
            json.put("historyId",ids)
            json.put("medicalHistory",medicName)
            var body=apiInterface().setUpdateUser(retrofits.getRequestBody(json.toString()))
            body.getCodeStatus(changeMedicSuccess,nowData)
        }
    }


}