package app.closer.data.repository

import app.closer.data.remote.FirestoreConversationDataSource
import app.closer.domain.model.Conversation
import app.closer.domain.model.QuestionMessage
import app.closer.domain.repository.ConversationRepository
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class ConversationRepositoryImpl @Inject constructor(
    private val dataSource: FirestoreConversationDataSource
) : ConversationRepository {

    override fun observeConversations(coupleId: String, currentUserId: String): Flow<List<Conversation>> =
        dataSource.observeConversations(coupleId, currentUserId)

    override suspend fun ensureMainConversation(coupleId: String) =
        dataSource.ensureMainConversation(coupleId)

    override suspend fun ensureQuestionConversation(coupleId: String, questionId: String): String =
        dataSource.ensureQuestionConversation(coupleId, questionId)

    override suspend fun markRead(coupleId: String, conversationId: String, userId: String) =
        dataSource.markRead(coupleId, conversationId, userId)

    override fun observeMessages(coupleId: String, conversationId: String, limit: Int): Flow<List<QuestionMessage>> =
        dataSource.observeMessages(coupleId, conversationId, limit)

    override fun observePartnerReadAt(coupleId: String, conversationId: String, currentUserId: String): Flow<Long> =
        dataSource.observePartnerReadAt(coupleId, conversationId, currentUserId)

    override fun setTyping(coupleId: String, conversationId: String, userId: String, typing: Boolean) =
        dataSource.setTyping(coupleId, conversationId, userId, typing)

    override fun observePartnerTyping(coupleId: String, conversationId: String, currentUserId: String): Flow<Long> =
        dataSource.observePartnerTyping(coupleId, conversationId, currentUserId)

    override suspend fun sendMessage(coupleId: String, conversationId: String, userId: String, text: String) =
        dataSource.sendMessage(coupleId, conversationId, userId, text)

    override suspend fun sendImageMessage(coupleId: String, conversationId: String, userId: String, imageBytes: ByteArray) =
        dataSource.sendImageMessage(coupleId, conversationId, userId, imageBytes)

    override suspend fun sendVoiceMessage(coupleId: String, conversationId: String, userId: String, audioBytes: ByteArray, durationMs: Long) =
        dataSource.sendVoiceMessage(coupleId, conversationId, userId, audioBytes, durationMs)

    override suspend fun setReaction(coupleId: String, conversationId: String, messageId: String, userId: String, emoji: String?) =
        dataSource.setReaction(coupleId, conversationId, messageId, userId, emoji)

    override suspend fun deleteMessage(coupleId: String, conversationId: String, messageId: String) =
        dataSource.deleteMessage(coupleId, conversationId, messageId)

    override suspend fun loadDecryptedMedia(coupleId: String, mediaUrl: String): ByteArray? =
        dataSource.loadDecryptedMedia(coupleId, mediaUrl)
}
