use std::path::Path;
use crate::io::csv::detections as csv_loader;
use crate::io::geojson::detections as geojson_loader;
use crate::models::{Detection, DetectionKind};
use super::error::DetectionError;
pub fn load_detections(
path: &Path,
expected_kind: DetectionKind,
) -> Result<Vec<Detection>, DetectionError> {
let ext = path
.extension()
.and_then(|s| s.to_str())
.map(|s| s.to_ascii_lowercase())
.unwrap_or_default();
match ext.as_str() {
"csv" => csv_loader::load(path, expected_kind),
"geojson" | "json" => geojson_loader::load(path, expected_kind),
_ => Err(DetectionError::UnsupportedExtension(ext)),
}
}