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

/// return field count
pub fn check_header(header: &Header) -> Result<usize> {
    let field_types_count = header.field_types().len();
    let field_names_count = header.field_names().len();
    if field_names_count != field_types_count {
        return Err(Error::from(format!(
            "there are {} field types but {} field names; expected them to be same",
            field_types_count, field_names_count
        )));
    }
    Ok(field_types_count)
}

pub fn check_row(row: impl AsRef<Row>, expected_field_count: usize) -> Result<()> {
    let row = row.as_ref();
    if row.field_values.len() == expected_field_count {
        Ok(())
    } else {
        return Err(Error::from(format!(
            "row has {} fields, but header had {}",
            row.field_values.len(),
            expected_field_count
        )));
    }
}
