// Project:   scalo
// File:      src/expression/mod.rs
// Purpose:   CEL expression evaluation for data-plane components
// Language:  Rust
//
// License:   Apache-2.0
// Copyright: (c) 2026 HYPERI PTY LIMITED

//! CEL expression evaluation -- compile, evaluate, validate.
//!
//! Provides a profile-restricted CEL expression evaluator built on the
//! [`cel`] crate (renamed from `cel-interpreter`). Both Python (via
//! `common-expression-language` PyO3 bindings) and Rust use the **same**
//! underlying Rust crate, ensuring identical parsing and evaluation
//! semantics across all data-plane components.
//!
//! # Expression Profile
//!
//! Only a high-performance subset of CEL is allowed:
//!
//! | Category | Examples |
//! |----------|---------|
//! | Comparison | `==`, `!=`, `<`, `<=`, `>`, `>=` |
//! | Logical | `&&`, `\|\|`, `!` |
//! | Membership | `in` |
//! | String | `contains()`, `startsWith()`, `endsWith()` |
//! | Existence | `has()` |
//! | Size | `size()` |
//! | Ternary | `? :` |
//! | Type casts | `int()`, `double()`, `string()`, `bool()` |
//! | Arithmetic | `+`, `-`, `*`, `/`, `%` |
//!
//! **Restricted (blocked by default, opt-in via [`ProfileConfig`]):**
//! - Regex: `matches()` -- unbounded cost per record
//! - Iteration: `map()`, `filter()`, `exists()`, `all()` -- O(n) per collection
//! - Time: `timestamp()`, `duration()` -- ClickHouse handles natively
//!
//! # Usage
//!
//! ```rust
//! use scalo::expression::{compile, evaluate, evaluate_condition, validate};
//! use std::collections::HashMap;
//! use serde_json::json;
//!
//! // Validate (returns errors list, empty if valid)
//! assert!(validate(r#"severity == "critical""#).is_empty());
//!
//! // One-shot evaluation
//! let mut data = HashMap::new();
//! data.insert("amount".into(), json!(15000));
//! let result = evaluate("amount > 10000", &data).unwrap();
//! assert_eq!(result, true.into());
//!
//! // Boolean condition (missing fields → false)
//! assert!(!evaluate_condition(r#"severity == "critical""#, &HashMap::new()));
//!
//! // Compile for hot-path reuse
//! let program = compile("score > threshold").unwrap();
//! // ... program.execute(&context) per record
//! ```
//!
//! See `dfe-engine/docs/EXPRESSIONS-CEL.md` for the full profile specification.

pub mod error;
pub mod evaluator;
pub mod profile;

pub use error::{ExpressionError, ExpressionResult};
pub use evaluator::{
    build_context, compile, compile_with_config, evaluate, evaluate_condition, validate,
    validate_with_config,
};
pub use profile::{
    ALLOWED_FUNCTIONS, DISALLOWED_FUNCTIONS, ProfileConfig, RESTRICTED_ITERATION, RESTRICTED_REGEX,
    RESTRICTED_TIME, check_profile_with_config,
};
