package com.renrenliao.im.viewmodel

import androidx.lifecycle.viewModelScope
import com.renrenliao.im.base.BaseViewModel
import com.renrenliao.im.im.AlarmEntity
import com.renrenliao.im.model.repository.LocalDataSource
import com.renrenliao.im.model.repository.RemoteDataSource
import com.renrenliao.im.utils.DataCacheUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
 **@ClassName AlarmViewModel
 **@Description
 **@Author gan
 **@Date 2022/6/16 15:50
 **/
class AlarmViewModel(private val remoteDataSource: RemoteDataSource,private val localDataSource: LocalDataSource):BaseViewModel() {


    val alarmLiveData = localDataSource.getAlarmsLiveData()

    //val avatarsLiveData = localDataSource.getAvatarsLiveData()

    fun deleteAlarm(alarmEntity: AlarmEntity){
        viewModelScope.launch{
            withContext(Dispatchers.IO){
                localDataSource.deleteAlarm(DataCacheUtils.getUid(),alarmEntity.gId.toString(),alarmEntity.msgType)
            }
        }
    }

    //更新置顶状态
    fun updateIsTop(account_uid: String,uid: String,msgType:Int,top:Boolean){
        viewModelScope.launch(Dispatchers.IO){
            localDataSource.updateIsTop(account_uid, uid, msgType, top)
        }
    }

    //更新已读未读状态
    fun updateReadStatus(account_uid: String,uid: String,msgType:Int,num:Int){
        viewModelScope.launch(Dispatchers.IO){
            localDataSource.updateReadStatus(account_uid, uid, msgType, num)
        }
    }



}