daa_rules/
actions.rs

1//! Action execution for rules
2
3use crate::{RuleAction, Result, RulesError, LogLevel};
4use crate::context::ExecutionContext;
5
6/// Action executor
7pub struct ActionExecutor;
8
9impl ActionExecutor {
10    /// Create a new action executor
11    pub fn new() -> Self {
12        Self
13    }
14
15    /// Execute an action
16    pub async fn execute_action(&self, action: &RuleAction, context: &mut ExecutionContext) -> Result<()> {
17        match action {
18            RuleAction::SetField { field, value } => {
19                context.set_variable(field.clone(), value.clone());
20                Ok(())
21            }
22            
23            RuleAction::Log { level, message } => {
24                match level {
25                    LogLevel::Trace => tracing::trace!("{}", message),
26                    LogLevel::Debug => tracing::debug!("{}", message),
27                    LogLevel::Info => tracing::info!("{}", message),
28                    LogLevel::Warn => tracing::warn!("{}", message),
29                    LogLevel::Error => tracing::error!("{}", message),
30                }
31                Ok(())
32            }
33            
34            RuleAction::ModifyContext { modifications } => {
35                for (key, value) in modifications {
36                    context.set_variable(key.clone(), value.clone());
37                }
38                Ok(())
39            }
40            
41            RuleAction::Abort { reason } => {
42                Err(RulesError::ActionExecution(format!("Execution aborted: {}", reason)))
43            }
44            
45            _ => {
46                // For other action types, log a warning
47                tracing::warn!("Unhandled action type: {:?}", action);
48                Ok(())
49            }
50        }
51    }
52}
53
54impl Default for ActionExecutor {
55    fn default() -> Self {
56        Self::new()
57    }
58}