package com.miya.fastcashier.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.miya.fastcashier.beans.ViewPayOrderData
import com.miya.fastcashier.dao.DatabaseKeeper
import com.miya.fastcashier.utils.MiYaPayPlantformPayWayEnum
import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.lang.Exception

class SearchOrderViewModel : ViewModel() {

    val payDataLiveData: MutableLiveData<Result<List<ViewPayOrderData>>> = MutableLiveData()

    /**
     * 获取
     */
    fun getPayData(payType: MiYaPayPlantformPayWayEnum.MiyaPayType, currentSize: Int) {
        viewModelScope.launch(Dispatchers.IO) {
            try {
                val list =
                    DatabaseKeeper.payDatabase.payDataDao()
                        .queryWithType(payType = payType.code, currentSize)
                payDataLiveData.postValue(Result.success(list))
            } catch (e: Exception) {
                e.printStackTrace()
                payDataLiveData.postValue(Result.failure(e))
            }

        }
    }
}