use arrow::array::{Float64Array, StringArray};
use arrow::datatypes::{DataType, Field, Schema};
use arrow::record_batch::RecordBatch;
use fuse_rule::{config::FuseRuleConfig, RuleEngine};
use std::sync::Arc;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt::init();
println!("🔥 FuseRule Basic Usage Example\n");
println!("📝 Loading configuration...");
let config = FuseRuleConfig::from_file("fuse_rule_config.yaml")?;
println!(" ✅ Loaded {} rules", config.rules.len());
println!("⚙️ Creating rule engine...");
let mut engine = RuleEngine::from_config(config).await?;
println!(" ✅ Engine created");
println!("📦 Creating test batch...");
let schema = Schema::new(vec![
Field::new("price", DataType::Float64, true),
Field::new("symbol", DataType::Utf8, true),
]);
let price_array = Arc::new(Float64Array::from(vec![1500.0, 500.0, 2000.0]));
let symbol_array = Arc::new(StringArray::from(vec!["AAPL", "GOOGL", "MSFT"]));
let batch = RecordBatch::try_new(Arc::new(schema), vec![price_array, symbol_array])?;
println!(" ✅ Created batch with {} rows", batch.num_rows());
println!("🔍 Processing batch and evaluating rules...\n");
let traces = engine.process_batch(&batch).await?;
println!("📊 Evaluation Results:");
println!("{}", "=".repeat(60));
for trace in traces {
let status = if trace.action_fired {
"🔥 FIRED"
} else {
"⚪"
};
println!("{} Rule: {} ({})", status, trace.rule_name, trace.rule_id);
println!(" Result: {:?}", trace.result);
println!(" Transition: {}", trace.transition);
if let Some(agent_status) = trace.agent_status {
println!(" Agent Status: {}", agent_status);
}
println!();
}
Ok(())
}