use tera::Context;
use serde_json::Value;
use std::collections::HashMap;
use chrono::{Utc, SecondsFormat};
use uuid::Uuid;
pub struct Replacer;
impl Replacer {
pub fn build_context(
request_json: Option<&Value>,
headers: &HashMap<String, String>,
query_params: &HashMap<String, String>,
path_segments: &[String],
model: &str,
) -> Context {
let mut context = Context::new();
context.insert("timestamp", &Utc::now().timestamp());
context.insert("iso_timestamp", &Utc::now().to_rfc3339_opts(SecondsFormat::Secs, true));
context.insert("uuid", &Uuid::new_v4().to_string());
context.insert("request_id", &format!("req_{}", &Uuid::new_v4().to_string()[..8]));
context.insert("model", model);
if let Some(json) = request_json {
context.insert("json", json);
}
context.insert("headers", headers);
context.insert("query", query_params);
context.insert("path_segments", path_segments);
context
}
}