package com.zj365.health.vm

import androidx.lifecycle.MutableLiveData
import com.xty.base.vm.BaseVm
import com.xty.network.model.BloodFatBean
import com.xty.network.model.Nation
import com.xty.network.model.NotAccepted
import com.xty.network.model.RespBody
import com.xty.network.model.SettingBean
import kotlinx.coroutines.async
import kotlinx.coroutines.withContext
import org.json.JSONObject

class BaseInfoVm : BaseVm() {

    val nationData by lazy { MutableLiveData<RespBody<MutableList<Nation>>>() }
    val updateSuccess by lazy { MutableLiveData<RespBody<SettingBean.User>>() }

    fun getNation() {
        startHttp {
            val body = apiInterface().getNations()
            body.getCodeStatus(nationData, nowData)
        }
    }

    fun saveInfo(
        id: String,
        name: String,
        sex: Int,
        birthdayType: Int,
        birthday: String,
        nation: String,
        height: String,
        weight: String,
        waistline: String,
        city: String?,
        province: String?,
        district: String?,
        hobby: String,
        religion: String
    ) {
        startHttp {
            val json = JSONObject()
            json.put("id", id)
            json.put("name", name)
            json.put("sex", sex)
            json.put("birthdayType", birthdayType)
            json.put("birthday", birthday)
            json.put("nation", nation)
            json.put("height", height)
            json.put("weight", weight)
            json.put("waistline", waistline)
            json.put("province", province)
            json.put("city", city)
            json.put("district", district)
            json.put("hobby", hobby)
            json.put("religion", religion)
            val body = apiInterface().updateUserInfo(retrofits.getRequestBody(json.toString()))
            body.getCodeStatus(updateSuccess, nowData)
        }
    }
}