package com.lukouguoji.hangban.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 HangBanQueryInfoViewModel : ViewModel() {

    private val logName = "GncQueryInfoViewModel"

    var wayBillInfo = JSONObject()

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

        }
    }

    fun queryFlightByIdHangBan(wbId: Int) {
        queryFlightByIdHangBanLiveData.value = wbId
    }


}