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

import android.content.Intent
import androidx.lifecycle.MutableLiveData
import com.lukouguoji.module_base.base.BaseViewModel
import com.lukouguoji.module_base.bean.GnjStashBean
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.util.DictUtils
import dev.utils.app.info.KeyValue

class GnjStashDetailsViewModel : BaseViewModel() {

    var id = ""

    val dataBean = MutableLiveData(GnjStashBean())

    val agentList = MutableLiveData<List<KeyValue>>().apply {
        DictUtils.getAgentList(addAll = false) {
            value = it
        }
    }
    val spCodeList = MutableLiveData<List<KeyValue>>().apply {
        DictUtils.getSpecialCodeList(addAll = false,flag = 0, ieFlag = "I") {
            value = it
        }
    }
    val waybillTypeList = MutableLiveData<List<KeyValue>>().apply {
        DictUtils.getWaybillTypeList2(type = "CI", addAll = false) {
            value = it
        }
    }
    val businessTypeList = MutableLiveData<List<KeyValue>>().apply {
        DictUtils.getBusinessTypeList(type = "CI", addAll = false) {
            value = it
        }
    }
    val packageTypeList = MutableLiveData<List<KeyValue>>().apply {
        DictUtils.getPacketTypeList(addAll = false) {
            value = it
        }
    }

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

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

        if (id.isNotEmpty()) {
            getDetails()
        }
    }

    /**
     * 获取详情
     */
    private fun getDetails() {
        launchLoadingCollect({
            NetApply.api.getGnjStashDetails(id)
        }) {
            onSuccess = {
                it.data?.let { data ->
                    dataBean.value = data
                }
            }
        }
    }

}