package com.seven.ikar.kotlin.feature.archive

import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow

sealed interface PendingArchiveOpen {
    val id: Long
}

data class PendingArchiveFile(
    override val id: Long = System.nanoTime(),
    val fileName: String,
    val contentType: String,
    val fileSizeBytes: Long,
    val localPath: String
) : PendingArchiveOpen

data class PendingArchiveOpenError(
    override val id: Long = System.nanoTime(),
    val fileName: String?,
    val message: String
) : PendingArchiveOpen

class IncomingArchiveStore {
    private val _pendingArchive = MutableStateFlow<PendingArchiveOpen?>(null)
    val pendingArchive: StateFlow<PendingArchiveOpen?> = _pendingArchive.asStateFlow()

    fun setPending(file: PendingArchiveFile) {
        _pendingArchive.value = file
    }

    fun setError(message: String, fileName: String? = null) {
        _pendingArchive.value = PendingArchiveOpenError(fileName = fileName, message = message)
    }

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