use crate::ops::rule::builder;
use crate::ir::Program;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RuleCondition {
PatternExists {
pattern_id: u32,
},
PatternCountGt {
pattern_id: u32,
threshold: u32,
},
PatternCountGte {
pattern_id: u32,
threshold: u32,
},
FileSizeLt(u64),
FileSizeLte(u64),
FileSizeGt(u64),
FileSizeGte(u64),
FileSizeEq(u64),
FileSizeNe(u64),
LiteralTrue,
LiteralFalse,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RuleFormula {
Condition(RuleCondition),
And(Box<RuleFormula>, Box<RuleFormula>),
Or(Box<RuleFormula>, Box<RuleFormula>),
Not(Box<RuleFormula>),
}
impl RuleFormula {
#[must_use]
pub fn condition(condition: RuleCondition) -> Self {
Self::Condition(condition)
}
#[must_use]
pub fn and(left: Self, right: Self) -> Self {
Self::And(Box::new(left), Box::new(right))
}
#[must_use]
pub fn or(left: Self, right: Self) -> Self {
Self::Or(Box::new(left), Box::new(right))
}
#[must_use]
pub fn not_formula(formula: Self) -> Self {
Self::Not(Box::new(formula))
}
#[must_use]
pub fn not(formula: Self) -> Self {
Self::not_formula(formula)
}
#[must_use]
pub fn to_program(&self) -> Program {
builder::build_rule_program(&[(self.clone(), 0)])
}
}