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 com.tencent.mmkv.MMKV
import kotlinx.coroutines.*

class PrintViewModel : ViewModel() {

    val printResultLiveData: MutableLiveData<Result<Any>> = MutableLiveData()
    val kv = MMKV.defaultMMKV()

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


}