use crate::domain::suppression_target::SuppressionTarget;
use crate::domain::Dimension;
#[derive(Debug, Clone, PartialEq)]
pub struct Suppression {
pub line: usize,
pub dimensions: Vec<Dimension>,
pub reason: Option<String>,
pub target: Option<SuppressionTarget>,
}
impl Suppression {
pub fn blanket(line: usize, dimensions: Vec<Dimension>, reason: Option<String>) -> Self {
Self {
line,
dimensions,
reason,
target: None,
}
}
pub fn covers(&self, dim: Dimension) -> bool {
self.dimensions.is_empty() || self.dimensions.contains(&dim)
}
pub fn suppresses(&self, dim: Dimension, target_name: &str, value: Option<f64>) -> bool {
if !self.covers(dim) {
return false;
}
match &self.target {
None => true,
Some(t) if t.name() == target_name => match t {
SuppressionTarget::Metric { pin, .. } => value.is_some_and(|v| v <= *pin),
SuppressionTarget::Boolean { .. } => true,
},
Some(_) => false,
}
}
}