package com.zj365.health.vm

import androidx.lifecycle.MutableLiveData
import com.xty.base.vm.BaseVm
import com.xty.network.model.RespBody
import com.xty.network.model.ShopOrderDetailBean
import com.xty.network.model.ShopOrderListBean
import org.json.JSONObject

class ShopOrderVm : BaseVm() {

    val shopOrderLiveDate by lazy { MutableLiveData<RespBody<ShopOrderListBean>>() }

    val orderDetailLiveData by lazy { MutableLiveData<RespBody<ShopOrderDetailBean>>() }

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

    val cancelOrderLiveData by lazy { MutableLiveData<RespBody<Any>>() }
    fun getOrderList(pageNum:Int,status:Int){

        startHttp {
            val json = JSONObject()
            json.put("pageNum",pageNum)
            json.put("pageSize", 10)
            json.put("status",status)

            val response = apiInterface().getShopOrderList(retrofits.getRequestBody(json.toString()))
            response.getCodeStatus(shopOrderLiveDate, nowData)
        }

    }

    fun getOrderDetail(id:Long){
        startHttp {
            val response =  apiInterface().getOrderDetail(id)
            response.getCodeStatus(orderDetailLiveData, nowData)

        }
    }

    fun receiveGoods(id:Long){
        startHttp {
            val response =  apiInterface().receiveGoods(id)
            response.getCodeStatus(receiveGoodsLiveData, nowData)

        }
    }


    fun cancelOrder(id:Long){
        startHttp {
            val response =  apiInterface().cancelOrder(id)
            response.getCodeStatus(cancelOrderLiveData, nowData)

        }
    }

    fun applyReturn(id:Long){
        startHttp {
            val response =  apiInterface().applyReturn(id)
            response.getCodeStatus(cancelOrderLiveData, nowData)

        }
    }
}