use super::Error;
use symphonia::core::errors::Error as SymError;
use rubato::{ResampleError, ResamplerConstructionError};

fn generic_map_error(action: &str, error_str: String) -> Error {
    Error::from_text(format!("symphonia error: {} during {}", error_str, action))
}

pub fn probe(error: SymError) -> Error {
    generic_map_error("probing of input", error.to_string())
}

pub fn decoder(error: SymError) -> Error {
    generic_map_error("finding codec", error.to_string())
}

pub fn next_packet(error: SymError) -> Error {
    generic_map_error("getting next raw packet", error.to_string())
}

pub fn decode(error: SymError) -> Error {
    generic_map_error("decoding of raw packet", error.to_string())
}

pub fn resampler_construction(error: ResamplerConstructionError) -> Error {
    generic_map_error("creating resampler", error.to_string())
}

pub fn resample(error: ResampleError) -> Error {
    generic_map_error("resampling", error.to_string())
}

pub fn find_track() -> Error {
    Error::from_str("symphonia error: No audio track located")
}