package dev.adriankuta.visualizer.domain

import androidx.compose.ui.graphics.Color
import dev.adriankuta.visualizer.data.AudioVisualizer
import dev.adriankuta.visualizer.data.WaveformFrame
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import javax.inject.Inject

class ObserveVisualizerColorUseCase @Inject constructor(
    private val audioVisualizer: AudioVisualizer
) {

    private val colorMapper = HSLSoundToColorMapper()

    operator fun invoke(): Flow<Color> =
        audioVisualizer.waveform()
            .map { processColor(it) }

    private fun processColor(waveformFrame: WaveformFrame): Color {
        return colorMapper.mapSoundToColor(waveformFrame.data)
    }
}