use crate::chopper::error::{Error, Result};
use crate::chopper::types::Header;
use crate::source::source::Source;

/// makes sure all the sources have the same header
pub fn get_header_from_sources(sources: &Vec<Box<dyn Source>>) -> Result<&Header> {
    if sources.is_empty() {
        return Err(Error::from("expected at least one source"));
    }

    let header = sources.get(0).unwrap().header();
    for i in 1..sources.len() {
        let other_header = sources.get(i).unwrap().header();
        if header != other_header {
            return Err(Error::from(format!(
                "source header mismatch found; \
                all inputs are expected to have same headers: {:?} vs {:?}",
                header, other_header
            )));
        }
    }
    Ok(header)
}
