use std::path::Path;
use dspk_core::{DspError, DspResult, RecordingSource};
use super::sources::{default_source, SourceEntry};
pub trait Format: Send + Sync {
fn name(&self) -> &'static str;
fn detect(&self, path: &Path) -> bool;
fn sources(&self, path: &Path) -> DspResult<Vec<SourceEntry>>;
fn open(&self, path: &Path, id: &str) -> DspResult<Box<dyn RecordingSource>>;
fn open_default(&self, path: &Path) -> DspResult<Box<dyn RecordingSource>> {
let list = self.sources(path)?;
let entry = default_source(&list)
.ok_or_else(|| DspError::UnsupportedFormat(format!("{} has no sources", path.display())))?;
self.open(path, &entry.id)
}
}