use crate::types::NodeId;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Severity {
Violation,
Warning,
Info,
}
#[derive(Debug, Clone)]
pub struct ConstraintViolation {
pub focus_node: NodeId,
pub shape_id: NodeId,
pub path: Option<String>,
pub message: String,
pub severity: Severity,
}
impl ConstraintViolation {
pub fn violation(
focus_node: NodeId,
shape_id: NodeId,
path: Option<String>,
message: impl Into<String>,
) -> Self {
Self {
focus_node,
shape_id,
path,
message: message.into(),
severity: Severity::Violation,
}
}
}
#[derive(Debug)]
pub struct ValidationReport {
pub conforms: bool,
pub violations: Vec<ConstraintViolation>,
}
impl ValidationReport {
pub fn from_violations(violations: Vec<ConstraintViolation>) -> Self {
let conforms = violations
.iter()
.all(|v| v.severity != Severity::Violation);
Self { conforms, violations }
}
pub fn conforms() -> Self {
Self { conforms: true, violations: vec![] }
}
}