///|
/// A machine-readable finding from a schema or table check.
pub using @core {type Diagnostic}

///|
/// Check one in-memory, comma-separated CSV against a Table Schema descriptor.
/// An empty result means all checks passed. Row numbers count data records
/// starting at one. Zero identifies schema, CSV syntax or header issues.
pub fn check_csv(
  schema_json : String,
  csv_text : String,
  resource~ : String = "table",
) -> Array[Diagnostic] {
  let schema = match @core.parse_table_schema(schema_json) {
    Ok(schema) => schema
    Err(errors) => return errors.map(e => { ..e, resource, })
  }
  let input = match @core.input_from_csv(resource, csv_text) {
    Ok(input) => input
    Err(message) =>
      return [{ code: "csv", resource, field: "", row: 0, message, }]
  }
  schema.validate(resource, input.header, input.rows).errors
}