package com.miya.fastcashier.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.miya.fastcashier.beans.LoginRequest
import com.miya.fastcashier.beans.SelfCashierAccountInfo
import com.miya.fastcashier.repository.PayRepository
import com.miya.fastcashier.service.AccountService
import com.miya.fastcashier.service.LoginService
import com.miya.fastcashier.service.PrintService
import com.sdy.miya.moblie.component.pay.platform.bean.MiyaOrderRefundResponse
import kotlinx.coroutines.*


class MainViewModel : ViewModel() {

    val refundLiveData: MutableLiveData<Result<PayRepository>> = MutableLiveData()

    /**
     * oriOrderNo 原订单号
     * refundOrderNo 退款订单号
     * refundPrice 退款金额
     */
    fun refund(oriOrderNo: String, refundOrderNo: String, refundPrice: String) = runBlocking {

        val refundParams = HashMap<String, String>()
        refundParams["oriOrderNo"] = oriOrderNo;
        refundParams["refundOrderNo"] = refundOrderNo;
        refundParams["refundPrice"] = refundPrice;

        val refundResult = async(Dispatchers.IO) {
            PayRepository.refundByOrderNo(refundParams)
        }

        val printResult = async(Dispatchers.IO) {
            AccountService.getAccountInfo()
                ?.let { PrintService.refundPrint(it, refundResult.await()) }
        }

        printResult.await()

//        refundLiveData.value = Result.success()

    }

}