using DeepDrftContent.FileDatabase.Models;
namespace DeepDrftContent.Processors;
///
/// Dispatches an audio file to the correct format processor by extension. The single seam through
/// which processes uploads, so callers depend on one abstraction
/// rather than three concrete processors.
///
public class AudioProcessorRouter
{
private readonly AudioProcessor _wavProcessor;
private readonly Mp3AudioProcessor _mp3Processor;
private readonly FlacAudioProcessor _flacProcessor;
public AudioProcessorRouter(
AudioProcessor wavProcessor,
Mp3AudioProcessor mp3Processor,
FlacAudioProcessor flacProcessor)
{
_wavProcessor = wavProcessor;
_mp3Processor = mp3Processor;
_flacProcessor = flacProcessor;
}
///
/// Processes with the processor matching its extension, returning an
/// carrying the stored bytes and extracted metadata. Throws
/// for unsupported extensions.
///
public async Task ProcessAudioFileAsync(string filePath)
{
var ext = Path.GetExtension(filePath).ToLowerInvariant();
return ext switch
{
".wav" => await _wavProcessor.ProcessWavFileAsync(filePath),
".mp3" => await _mp3Processor.ProcessMp3FileAsync(filePath),
".flac" => await _flacProcessor.ProcessFlacFileAsync(filePath),
_ => throw new ArgumentException($"Unsupported audio format: {ext}", nameof(filePath)),
};
}
}