package com.renrenliao.im.db

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.renrenliao.im.im.GroupEntity
import kotlinx.coroutines.flow.Flow

/**
 **@ClassName TestDao
 **@Description
 **@Author gan
 **@Date 2022/5/25 14:41
 **/

@Dao
interface GroupDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertGroup(group: GroupEntity)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertGroups(groups: List<GroupEntity>)

    @Query("SELECT * FROM groups WHERE account_uid = :account_uid")
    fun getGroups(account_uid: String): List<GroupEntity>

    @Query("SELECT * FROM groups WHERE account_uid = :account_uid")
    fun getGroupsLiveData(account_uid: String): Flow<List<GroupEntity>>

    //    @Query("UPDATE friend SET userAvatarFileName = :avatarUrl where userUid = :userUid")
//    fun updateFriendAvatar(userUid:Int,avatarUrl:String)
    @Query("delete FROM groups")
    fun deleteAllGroup()
}