package com.lukouguoji.gnc.page.query.details

import android.content.Intent
import androidx.lifecycle.MutableLiveData
import com.alibaba.android.arouter.launcher.ARouter
import com.lukouguoji.gnc.R
import com.lukouguoji.module_base.base.BaseViewModel
import com.lukouguoji.module_base.bean.GncQueryBean
import com.lukouguoji.module_base.bean.GncQueryDetailsBean
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 GncQueryDetailsViewModel : BaseViewModel() {

    var id = ""

    val dataBean = MutableLiveData<GncQueryBean>()

    val list = MutableLiveData<List<GncQueryDetailsBean.WhBean>>()

    val viewHolder = GncQueryDetailsViewHolder::class.java
    val itemLayoutId = R.layout.item_gnc_query_details

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

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

        getData()
    }

    private fun getData() {
        launchLoadingCollect({
            NetApply.api.getGncQueryDetails(id)
        }) {
            onSuccess = {
                dataBean.value = it.data?.maWb ?: GncQueryBean()
                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.exportStatus)
            .withString("wbNoParam", dataBean.value!!.wbNo)
            .navigation()
    }

}