package com.miya.fastcashier.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.miya.fastcashier.service.AccountService
import com.miya.fastcashier.service.PrintService
import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class PrintViewModel : ViewModel() {

    val printResultLiveData: MutableLiveData<Result<Any>> = MutableLiveData()

    fun printOrder(payServiceResponse: PayServiceResponse){
        //todo 检查参数
        viewModelScope.launch(Dispatchers.IO){
            try {
                AccountService.getAccountInfo()?.let {
                    PrintService.payPrint(payServiceResponse, it)
                }
                printResultLiveData.postValue(Result.success(Any()))
            }catch (e:Exception){
                printResultLiveData.postValue(Result.failure(e))
            }
        }
    }


}