package com.seven.ikar.kotlin.feature.share

import com.seven.ikar.kotlin.feature.chat.LocalAttachmentFile
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow

data class PendingExternalShare(
    val id: Long = System.nanoTime(),
    val text: String? = null,
    val attachments: List<LocalAttachmentFile> = emptyList()
) {
    val hasContent: Boolean
        get() = !text.isNullOrBlank() || attachments.isNotEmpty()
}

class IncomingShareStore {
    private val _pendingShare = MutableStateFlow<PendingExternalShare?>(null)
    val pendingShare: StateFlow<PendingExternalShare?> = _pendingShare.asStateFlow()

    fun setPending(share: PendingExternalShare?) {
        _pendingShare.value = share?.takeIf(PendingExternalShare::hasContent)
    }

    fun clear() {
        _pendingShare.value = null
    }
}
