/*
 * F7cloud Talk - Android Client
 *
 * SPDX-FileCopyrightText: 2024 Marcel Hibbe <dev@mhibbe.de>
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

package ru.f7cloud.talk.conversationlist.data

import ru.f7cloud.talk.data.user.model.User
import ru.f7cloud.talk.models.domain.ConversationModel
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow

interface OfflineConversationsRepository {

    /**
     * Stream of a list of rooms, for use in the conversation list.
     */
    val roomListFlow: Flow<List<ConversationModel>>

    /**
     * Stream of a single conversation, for use in each conversations settings.
     */
    val conversationFlow: Flow<ConversationModel>

    /**
     * Loads rooms from local storage. If the rooms are not found, then it
     * synchronizes the database with the server, before retrying exactly once. Only
     * emits to [roomListFlow] if the rooms list is not empty.
     *
     */
    fun getRooms(user: User): Job

    /**
     * Called once onStart to emit a conversation to [conversationFlow]
     * to be handled asynchronously.
     */
    fun getRoom(user: User, roomToken: String): Job

    suspend fun updateConversation(conversationModel: ConversationModel)

    suspend fun getLocallyStoredConversation(user: User, roomToken: String): ConversationModel?
}
