package ru.forbion.f7cloud.feature.talk

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query

@Dao
interface TalkOfflineDao {
    @Query("SELECT * FROM talk_rooms ORDER BY lastActivity DESC")
    suspend fun allRooms(): List<TalkRoomEntity>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun upsertRooms(rooms: List<TalkRoomEntity>)

    @Query("SELECT * FROM talk_messages WHERE roomToken = :token ORDER BY id ASC")
    suspend fun messagesForRoom(token: String): List<TalkMessageEntity>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun upsertMessages(messages: List<TalkMessageEntity>)

    @Query("DELETE FROM talk_messages WHERE roomToken = :token")
    suspend fun clearMessages(token: String)
}
