package top.yeij.cyrene.domain.repository

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import top.yeij.cyrene.domain.model.Conversation
import top.yeij.cyrene.domain.model.Message

interface ChatRepository {

    val connectionState: StateFlow<Boolean>
    val connectionError: StateFlow<String?>
    val isAssistantStreaming: StateFlow<Boolean>
    val messageClearEvents: Flow<Unit>
    val messageRemovals: Flow<String>
    var currentSessionId: String?

    fun getConversations(): Flow<List<Conversation>>

    suspend fun getMessages(conversationId: String): Flow<List<Message>>

    suspend fun deleteConversation(id: String)

    suspend fun connectWebSocket(sessionId: String?)

    suspend fun sendMessage(content: String, sessionId: String?, attachments: List<top.yeij.cyrene.data.remote.dto.WSAttachment>? = null, localImageUris: List<String> = emptyList())

    fun observeMessages(): Flow<Message>

    suspend fun loadConversationsFromServer()

    suspend fun loadMessagesFromServer(sessionId: String): List<Message>

    suspend fun initializeSession(): String

    suspend fun reconnectWebSocket()

    suspend fun ensureConnected()

    suspend fun sendScreenContext(content: String)

    suspend fun sendVoiceInput(audioBase64: String, mode: String = "voice_msg")

    suspend fun clearLocalMessages()

    fun onAppForeground()
    fun onAppBackground()
}
