package dev.adriankuta.visualizer.di

import android.media.audiofx.Visualizer
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import dev.adriankuta.visualizer.data.AudioVisualizer
import dev.adriankuta.visualizer.data.AudioVisualizerController
import dev.adriankuta.visualizer.data.AudioVisualizerImpl
import dev.adriankuta.visualizer.domain.processors.FftToColor
import dev.adriankuta.visualizer.domain.processors.HSLSoundToColorMapper
import dev.adriankuta.visualizer.domain.processors.VisualizerProcessor
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
abstract class VisualizerModule {

    @Binds
    abstract fun bindVisualizer(
        audioVisualizerImpl: AudioVisualizerImpl
    ): AudioVisualizer

    @Binds
    abstract fun bindVisualizerToController(
        audioVisualizerImpl: AudioVisualizerImpl
    ): AudioVisualizerController

    /*@Binds
    abstract fun bindFftProcessor(
        fftToColor: WaveformToColorProcessor
    ): VisualizerProcessor*/

    companion object {
        @Provides
        @Singleton
        fun provideVisualizer(): Visualizer {
            return Visualizer(0).apply {
                captureSize = 1024
            }
        }

        @Provides
        @Singleton
        fun provideProcessor(): VisualizerProcessor {
            return HSLSoundToColorMapper()
        }
    }
}