use std::path::Path;

use lumotia_core::error::Result;
use lumotia_core::types::AudioSamples;

use crate::decode::decode_audio_file;
use crate::resample::resample_to_16khz;

/// Decode and resample an audio file on a blocking thread.
/// Returns 16kHz mono AudioSamples ready for transcription.
pub async fn decode_and_resample(path: &Path) -> Result<AudioSamples> {
    let path = path.to_path_buf();
    tokio::task::spawn_blocking(move || {
        let audio = decode_audio_file(&path)?;
        resample_to_16khz(&audio)
    })
    .await
    .map_err(|e| lumotia_core::error::Error::AudioDecodeFailed(format!("Task join error: {e}")))?
}
