package com.qimai.log.database

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

/**
 * 获取数据库操作类
 */
class PushDataBaseVm(application: Application) : AndroidViewModel(application) {
    private val mDataBse: PushNotifiInfoDao by lazy {
        PushNotifiDataBase.getDatabase(application).pushInfoDao()
    }

    fun insertPushInfo(notifiInfo: PushNotifiInfo) {
        viewModelScope.launch(Dispatchers.IO) {
            mDataBse.insert(notifiInfo)
        }
    }

    fun updatePushInfo(msg_id: String, status: Boolean, errorMsg: String? = null) {
        viewModelScope.launch(Dispatchers.IO) {
            mDataBse.updateStatus(msg_id, status, errorMsg)
        }
    }
}