package com.zj365.health.vm

import android.text.TextUtils
import androidx.lifecycle.MutableLiveData
import com.xty.base.vm.BaseVm
import com.xty.network.model.NSuanOpenBean
import com.xty.network.model.OpenOrRenewBean
import com.xty.network.model.RespBody
import com.xty.network.model.UricAcidUserBean
import org.json.JSONObject

class NSuanVm : BaseVm() {

    val nsuanOpen by lazy { MutableLiveData<RespBody<NSuanOpenBean>>() }
    val nsUpdataData by lazy { MutableLiveData<RespBody<Any>>() }
    val userInfo by lazy { MutableLiveData<RespBody<UricAcidUserBean>>() }
    val renewOpenData by lazy { MutableLiveData<RespBody<OpenOrRenewBean>>() }

    /**
     * 尿酸开通/尿酸续费
     * @param code 激活码
     */
    fun nsOpen(userId: String, code: String) {
        startHttp(true) {
            val json = JSONObject()
            json.put("userId", userId)
            json.put("code", code)
            val value = apiInterface().nsOpen(retrofits.getRequestBody(json.toString()))
            value.getCodeStatus(nsuanOpen, nowData)
        }
    }

    /**
     * 血糖尿酸血脂续费（新）
     */
    fun renewOpenRequest(
        userId: String,//用户ID
        subject: Int,//3，血糖续费开通，4，尿酸续费开通，5，血脂续费开通
        channelName: String,//支付方式（ALIPAY_APP：支付宝支付，WEIXIN_APP：微信支付，EXCHANGE_CODE：兑换码兑换
        exchangeCode: String//兑换码
    ) {
        startHttp {
            val json = JSONObject()
            json.put("id", userId)
            json.put("subject", subject)
            json.put("channelName", channelName)
            if (!TextUtils.isEmpty(exchangeCode)) {
                json.put("exchangeCode", exchangeCode)
            }
            val renewOpen = apiInterface().renewOpen(retrofits.getRequestBody(json.toString()))
            renewOpen.getCodeStatus(renewOpenData, nowData)
        }
    }

    /**
     * 尿酸更新用户其他信息
     * @param userId 用户ID
     * @param smokeState 抽烟状态0，不抽，1，偶尔，2，经常
     * @param drinkState 饮酒状态0，不抽，1，偶尔，2，经常
     * @param height 身高
     * @param weight 体重
     */
    fun nsUpdataMes(
        userId: String,
        smokeState: String,
        drinkState: String,
        height: String,
        weight: String
    ) {
        startHttp(true) {
            val json = JSONObject()
            json.put("id", userId)
            json.put("smokeState", smokeState)
            json.put("drinkState", drinkState)
            json.put("height", height)
            json.put("weight", weight)
            val value = apiInterface().nsUpdataMessage(retrofits.getRequestBody(json.toString()))
            value.getCodeStatus(nsUpdataData, nowData)
        }
    }

    fun getUserInfo(id:String){
        startHttp(false){
            val json= JSONObject()
            json.put("id",id)

            val body = apiInterface().getUserOtherInfo(retrofits.getRequestBody(json.toString()))
            body.getCodeStatus(userInfo,nowData)
        }
    }
}