#![allow(dead_code)]
use serde_json::{Value, json};
use crate::validation;
use moltendb_core::{engine, analytics};
pub fn process_analytics(db: &engine::Db, payload: &Value, max_body_size: usize) -> Value {
if let Err(e) = validation::validate_request(payload, max_body_size) {
return json!({ "error": e.to_string() });
}
let query: analytics::AnalyticsQuery = match serde_json::from_value(payload.clone()) {
Ok(q) => q,
Err(e) => return json!({ "error": format!("Invalid analytics query: {}", e) }),
};
let result = analytics::execute_query(db, &query);
json!({
"result": result.result,
"metadata": {
"execution_time_ms": result.metadata.execution_time_ms,
"rows_scanned": result.metadata.rows_scanned
}
})
}