#![deny(clippy::pedantic)]
use std::collections::HashMap;
use anyhow::Result;
use opa_wasm::Runtime;
use wasmtime::{Engine, Module, Store};
#[tokio::main]
async fn main() -> Result<()> {
let engine = Engine::default();
let module = tokio::fs::read("./policy.wasm").await?;
let module = Module::new(&engine, module)?;
let mut store = Store::new(&engine, ());
let data = HashMap::from([("hello", "world")]);
let input = HashMap::from([("message", "world")]);
let runtime = Runtime::new(&mut store, &module).await?;
let policy = runtime.with_data(&mut store, &data).await?;
let res: serde_json::Value = policy.evaluate(&mut store, "hello/world", &input).await?;
println!("{res}");
Ok(())
}