package dev.adriankuta.visualizer.data

import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class RmsValueProvider @Inject constructor() {

    private val currentRms =
        MutableSharedFlow<RmsValue>(1, 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)

    fun emit(value: RmsValue) {
        currentRms.tryEmit(value)
    }

    fun observe(): SharedFlow<RmsValue> = currentRms
}

data class RmsValue(
    val current: Double,
    val max: Double,
    val min: Double = 0.0
)