use std::collections::HashMap;
use uni_cypher::ast::{Clause, Expr, Pattern, Query};
use uni_cypher::locy_ast::{
AbduceQuery, AlongBinding, BestByClause, DeriveCommand, ExplainRule, FoldBinding, GoalQuery,
RuleCondition, RuleOutput,
};
#[derive(Debug, Clone)]
pub struct CompiledProgram {
pub strata: Vec<Stratum>,
pub rule_catalog: HashMap<String, CompiledRule>,
pub warnings: Vec<CompilerWarning>,
pub commands: Vec<CompiledCommand>,
}
#[derive(Debug, Clone)]
pub enum CompiledCommand {
GoalQuery(GoalQuery),
Assume(CompiledAssume),
Abduce(AbduceQuery),
ExplainRule(ExplainRule),
DeriveCommand(DeriveCommand),
Cypher(Query),
}
#[derive(Debug, Clone)]
pub struct CompiledAssume {
pub mutations: Vec<Clause>,
pub body_program: CompiledProgram,
pub body_commands: Vec<CompiledCommand>,
}
#[derive(Debug, Clone)]
pub struct Stratum {
pub id: usize,
pub rules: Vec<CompiledRule>,
pub is_recursive: bool,
pub depends_on: Vec<usize>,
}
#[derive(Debug, Clone)]
pub struct CompiledRule {
pub name: String,
pub clauses: Vec<CompiledClause>,
pub yield_schema: Vec<YieldColumn>,
pub priority: Option<i64>,
}
#[derive(Debug, Clone)]
pub struct CompiledClause {
pub match_pattern: Pattern,
pub where_conditions: Vec<RuleCondition>,
pub along: Vec<AlongBinding>,
pub fold: Vec<FoldBinding>,
pub having: Vec<Expr>,
pub best_by: Option<BestByClause>,
pub output: RuleOutput,
pub priority: Option<i64>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct YieldColumn {
pub name: String,
pub is_key: bool,
pub is_prob: bool,
}
#[derive(Debug, Clone)]
pub struct CompilerWarning {
pub code: WarningCode,
pub message: String,
pub rule_name: String,
}
#[derive(Debug, Clone, PartialEq)]
pub enum WarningCode {
MsumNonNegativity,
ProbabilityDomainViolation,
}
#[derive(Debug, Clone, PartialEq)]
pub enum RuntimeWarningCode {
SharedProbabilisticDependency,
BddLimitExceeded,
CrossGroupCorrelationNotExact,
}
#[derive(Debug, Clone)]
pub struct RuntimeWarning {
pub code: RuntimeWarningCode,
pub message: String,
pub rule_name: String,
pub variable_count: Option<usize>,
pub key_group: Option<String>,
}