package com.lukouguoji.aerologic.page.gnj.query.details

import android.content.Intent
import androidx.lifecycle.MutableLiveData
import com.alibaba.android.arouter.launcher.ARouter
import com.lukouguoji.aerologic.R
import com.lukouguoji.module_base.base.BaseViewModel
import com.lukouguoji.module_base.bean.GncQueryDetailsBean
import com.lukouguoji.module_base.bean.GnjQueryBean
import com.lukouguoji.module_base.bean.GnjQueryDetailsBean
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.http.net.NetApply
import com.lukouguoji.module_base.ktx.launchLoadingCollect
import com.lukouguoji.module_base.router.ARouterConstants

class GnjQueryDetailsViewModel : BaseViewModel() {

    var id = ""

    val dataBean = MutableLiveData(GnjQueryBean())

    val itemLayoutId = R.layout.item_gnj_query_details
    val viewHolder = GnjQueryDetailsViewHolder::class.java

    val list = MutableLiveData<List<GnjQueryDetailsBean.Wh>>()

    ///////////////////////////////////////////////////////////////////////////
    // 方法区
    ///////////////////////////////////////////////////////////////////////////

    fun initOnCreated(intent: Intent) {
        id = intent.getStringExtra(Constant.Key.ID) ?: ""

        getData()
    }

    private fun getData() {
        launchLoadingCollect({
            NetApply.api.getGnjQueryDetails(id)
        }) {
            onSuccess = {
                dataBean.value = it.data?.maWb ?: GnjQueryBean()
                list.value = it.data?.whList ?: emptyList()
            }
        }
    }

    fun onFlowChartClick() {
        ARouter.getInstance().build(ARouterConstants.ACTIVITY_URL_CARGO_TRACKING)
            .withString("countryTypeParam", Constant.CargoTracking.gnStatus)
            .withString("ieFlagParam", Constant.CargoTracking.importStatus)
            .withString("wbNoParam", dataBean.value!!.wbNo)
            .navigation()
    }
}