use super::{Diagnostic, Severity};
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct DiagnosticReport {
pub diagnostics: Vec<Diagnostic>,
}
pub type ValidationReport = DiagnosticReport;
impl DiagnosticReport {
#[must_use]
pub fn new() -> Self {
Self::default()
}
pub fn push(&mut self, diagnostic: Diagnostic) {
self.diagnostics.push(diagnostic);
}
pub fn merge(&mut self, other: DiagnosticReport) {
self.diagnostics.extend(other.diagnostics);
}
#[must_use]
pub fn is_valid(&self) -> bool {
!self.diagnostics.iter().any(|d| d.severity.is_error())
}
#[must_use]
pub fn with_min_severity(&self, min: Severity) -> Vec<&Diagnostic> {
self.diagnostics
.iter()
.filter(|d| d.severity >= min)
.collect()
}
#[must_use]
pub fn errors(&self) -> Vec<&Diagnostic> {
self.with_min_severity(Severity::Error)
}
}