package com.adealink.weparty.call.viewmodel

import com.adealink.frame.base.Rlt
import com.adealink.frame.mvvm.livedata.ExtMutableLiveData
import com.adealink.frame.mvvm.viewmodel.BaseViewModel
import com.adealink.weparty.module.order.OrderModule
import com.adealink.weparty.module.order.data.OrderDetailInfo
import kotlinx.coroutines.launch

class CallOrderViewModel : BaseViewModel() {

    val pendingOrderLd = ExtMutableLiveData<Rlt<OrderDetailInfo?>>()

    fun loadTopInfo(uid: String) {
        viewModelScope.launch {
            val rlt = OrderModule.queryUnCompleteOrder(uid)
            when (rlt) {
                is Rlt.Failed -> {
                    pendingOrderLd.send(rlt)
                }

                is Rlt.Success -> {
                    val pendingOrder = rlt.data.firstOrNull()
                    pendingOrderLd.send(Rlt.Success(pendingOrder))
                }
            }
        }
    }
}