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

    /**
     * 完成复磅
     */
    private val completedLiveData = MutableLiveData<JSONObject>()
    val completedObserver = Transformations.switchMap(completedLiveData) { param ->
        liveData(Dispatchers.IO) {
            try {
                val response = UserNetwork.completedMitInPack(param!!)
                emit(response)
            } catch (e: Exception) {
                Log.e("GoutStartViewModel", e.stackTraceToString())
            }

        }
    }

    fun completed(fid: Int, carId: String) {
        val jsonObject = JSONObject()
        jsonObject["fid"] = fid
        jsonObject["carId"] = carId
        completedLiveData.value = jsonObject
    }
}