package com.grkj.iscs_mc.view.presenter

import com.grkj.iscs_mc.extentions.serialNo
import com.grkj.iscs_mc.model.vo.material.MaterialDetailRespVO
import com.grkj.iscs_mc.model.vo.material.MaterialListRespVO
import com.grkj.iscs_mc.util.Executor
import com.grkj.iscs_mc.util.NetApi
import com.grkj.iscs_mc.view.base.BasePresenter
import com.grkj.iscs_mc.view.iview.IMaterialFetchReturnView

class MaterialFetchReturnPresenter : BasePresenter<IMaterialFetchReturnView>() {

    fun getMaterialList(callBack: (MutableList<MaterialListRespVO>?) -> Unit) {
        NetApi.getMaterialList(mContext!!.serialNo()) {
            val rfidList = it?.flatMap { it.materials.orEmpty() }
                ?.filter { !it.materialsRfid.isNullOrBlank() }
                ?.map { it.materialsRfid!! }
                ?.toMutableList()
            rfidList?.let { itList ->
                getMaterialDetailListByRfid(itList) {

                }
//                getMaterialDetailByRfid(itList[0]) {
//
//                }
            }
            Executor.runOnMain {
                callBack(it)
            }
        }
    }

    private fun getMaterialDetailListByRfid(rfidList: MutableList<String>, callBack: (MutableList<MaterialDetailRespVO>?) -> Unit) {
        NetApi.getMaterialDetailListByRfid(rfidList) {
            Executor.runOnMain {
                callBack(it)
            }
        }
    }

    private fun getMaterialDetailByRfid(rfid: String, callBack: (MaterialDetailRespVO?) -> Unit) {
        NetApi.getMaterialDetailByRfid(rfid) {
            Executor.runOnMain {
                callBack(it)
            }
        }
    }
}