package com.lukouguoji.gnj.viewModel

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData
import com.alibaba.fastjson.JSONObject
import com.lukouguoji.module_base.http.user.UserNetwork
import kotlinx.coroutines.Dispatchers

class GnjWareHouseInfoViewModel : ViewModel() {

    private val logName = "GncQueryInfoViewModel"

    var wayBillInfo = JSONObject()

    /**
     * 出港查询详情
     */
    private val queryInfoByIdGnjWareHouseLiveData = MutableLiveData<Int>()
    val queryInfoByIdGnjWareHouseObserver = Transformations.switchMap(queryInfoByIdGnjWareHouseLiveData) { param ->
        liveData(Dispatchers.IO) {
            try {
                var response = JSONObject()
                if (param != -9999) {
                    response = UserNetwork.queryInfoByIdGnjWareHouse(param.toString())
                }
                emit(response)
            } catch (e: Exception) {
                Log.e(logName, e.stackTraceToString())
            }

        }
    }

    fun queryInfoByIdGnjWareHouse(wbId: Int) {
        queryInfoByIdGnjWareHouseLiveData.value = wbId
    }


}