package com.zj365.health.vm

import androidx.lifecycle.MutableLiveData
import com.xty.base.vm.BaseVm
import com.xty.common.util.CommonToastUtils
import com.zj365.health.R
import com.xty.network.model.FamilyBean
import com.xty.network.model.FriendInfo
import com.xty.network.model.RespBody
import org.json.JSONObject

class BindFamilyVm: BaseVm() {
    val bindOk by lazy{MutableLiveData<RespBody<String>>()}
    val changeOk by lazy{MutableLiveData<RespBody<String>>()}
    val friendLive by lazy{MutableLiveData<RespBody<FriendInfo>>()}
    fun bindDev(nickName:String,devNum:String,code:String,typeName:String){
        if(devNum.isNullOrEmpty()){
            CommonToastUtils.showToast(R.string.please_input_device_code)
            return
        }
        if(code.isNullOrEmpty()){
            CommonToastUtils.showToast(R.string.please_input_active_code)
            return

        }
        startHttp {
            var json=JSONObject()
            json.put("fCall",nickName)
            json.put("deviceCode",devNum)
            json.put("activationCode",code)
            json.put("type",typeName)
            var response =apiInterface().bindDev(retrofits.getRequestBody(json.toString()))
            response.getCodeStatus(bindOk,nowData)
        }
    }



    //修改昵称
    fun changeFamilyNickName(bean: FamilyBean?, nickName:String?,typeName:String?){
        startHttp {
            var json=JSONObject()
            json.put("id",bean?.id)
            json.put("userJointId",bean?.userJointId)
            json.put("fCall",nickName)
            json.put("type",typeName)
            var response=  apiInterface().changeFamilyNickName(retrofits.getRequestBody(json.toString()))
            response.getCodeStatus(changeOk,nowData)
        }
    }

    fun getFriendInfo(id:Int,userId:String){
        startHttp {
            var json=JSONObject()
            json.put("id",id)
            json.put("userId",userId)
            var body=apiInterface().getFriendInfo(retrofits.getRequestBody(json.toString()))
            body.getCodeStatus(friendLive,nowData)

        }
    }
}