package com.zj365.health.vm

import androidx.lifecycle.MutableLiveData
import com.xty.base.vm.BaseVm
import com.xty.network.model.FamilyGuardianBean
import com.xty.network.model.FamilyHealthBean
import com.xty.network.model.InviteCustodyBean
import com.xty.network.model.RespBody
import org.json.JSONObject

class FamilyHealthVm :BaseVm() {

    val familyHealthListData by lazy { MutableLiveData<RespBody<MutableList<FamilyHealthBean>>>() }

    val familyGuardianLiveData by lazy { MutableLiveData<RespBody<MutableList<FamilyGuardianBean>>>() }

    val exitCustody by lazy { MutableLiveData<RespBody<Any>>() }

    val firstGuardianLiveData by lazy { MutableLiveData<RespBody<Any>>() }

    val deleteGuardianLiveData by  lazy { MutableLiveData<RespBody<Any>>() }

    val findInfoLiveData by lazy { MutableLiveData<RespBody<InviteCustodyBean>>() }

    val confirmInviteLiveData by lazy { MutableLiveData<RespBody<Any>>() }

    fun getFamilyHealthList(){
        startHttp (true){

            val json = JSONObject()
            val request = apiInterface().getFamilyList(retrofits.getRequestBody(json.toString()))
            request.getCodeStatus(familyHealthListData,nowData)
        }
    }

    fun exitCustody(id:String){
        startHttp (true){
            val request = apiInterface().exitCustody(id)
            request.getCodeStatus(exitCustody,nowData)
        }
    }

    fun getFamilyHealthGuardianList(){
        startHttp (true){

            val json = JSONObject()
            val request = apiInterface().getFamilyGuardianList(retrofits.getRequestBody(json.toString()))
            request.getCodeStatus(familyGuardianLiveData,nowData)
        }
    }


    fun setFirstGuardian(id:Long){
        startHttp  {
            val json = JSONObject()
            json.put("id",id)
            val request = apiInterface().setFirstGuardian(retrofits.getRequestBody(json.toString()))
            request.getCodeStatus(firstGuardianLiveData,nowData)
        }
    }

    fun deleteGuardian(id:Long){
        startHttp  {
            val json = JSONObject()
            json.put("id",id)
            val request = apiInterface().deleteGuardian(retrofits.getRequestBody(json.toString()))
            request.getCodeStatus(deleteGuardianLiveData,nowData)
        }
    }

    fun searchInviteInfo(){
        startHttp(false) {
            var json = JSONObject()
            val response = apiInterface().findConfirmInfo(retrofits.getRequestBody(json.toString()))
            response.getCodeStatus(findInfoLiveData, nowData)
        }
    }

    fun confirmInvite(id:String, status:String){
        startHttp(false) {
            var json = JSONObject()
            json.put("id",id)
            json.put("status",status)
            val response = apiInterface().confirmInvited(retrofits.getRequestBody(json.toString()))
            response.getCodeStatus(confirmInviteLiveData,nowData)
        }

    }


}