package cn.muchinfo.rma.view.base.home.registration

import androidx.lifecycle.MutableLiveData
import cn.muchinfo.rma.netManage.base.InteractiveException
import cn.muchinfo.rma.protobuf.protoclasses.ErmcpMI1
import cn.muchinfo.rma.view.MyApplication
import cn.muchinfo.rma.view.base.BaseViewModel
import com.blankj.utilcode.util.ToastUtils
import mtp.polymer.com.autowidget.utils.TaskUiModel

class RegistrationViewModel : BaseViewModel(){


    /**
     * 加载状态控制
     */
    val loadingDialogStatus: MutableLiveData<TaskUiModel> = MutableLiveData()


    /**
     * 合同
     * @param info ContractOperateApplyInfo 操作信息
     * @param operateType Int 操作类型-1:登记2:确认3：拒绝4：撤销
     * @param remark String 备注
     * @param operateApplyID Long 暂时传0 操作申请ID(603+Unix秒时间戳(10位)+xxxxxx)//不知道是啥玩意
     * @param isSuccess Function1<[@kotlin.ParameterName] Boolean, Unit>
     */
    fun orderPerationContract(
        info: ErmcpMI1.ContractOperateApplyInfo,
        operateType: Int = 0,
        remark: String = "",
        isSuccess: (isCompleted: Boolean) -> Unit
    ) {
        loadingDialogStatus.postValue(TaskUiModel.inFlight())
        MyApplication.getInstance()?.contractManager?.orderPerationContract(info = info,operateType = operateType,remark = remark){ isCompleted, err ->
            if (isCompleted){
                ToastUtils.showLong("请求成功")
                loadingDialogStatus.postValue(TaskUiModel.success(msg = "请求成功"))
                isSuccess(true)
            }else{
                loadingDialogStatus.postValue(TaskUiModel.failed(InteractiveException(errorMessage = err?.message!!)))
            }
        }
    }

}