use std::sync::Arc;
use turbovault_audit::{AuditEntry, AuditFilter, AuditLog, AuditStats};
use turbovault_audit::{RollbackEngine, RollbackPreview, RollbackResult, SnapshotStore};
use turbovault_core::prelude::*;
pub struct AuditTools {
audit_log: Arc<AuditLog>,
snapshot_store: Arc<SnapshotStore>,
}
impl AuditTools {
pub fn new(audit_log: Arc<AuditLog>, snapshot_store: Arc<SnapshotStore>) -> Self {
Self {
audit_log,
snapshot_store,
}
}
pub async fn query_log(&self, filter: &AuditFilter) -> Result<Vec<AuditEntry>> {
self.audit_log.query(filter).await
}
pub async fn stats(&self) -> Result<AuditStats> {
self.audit_log.stats().await
}
pub async fn rollback_preview(
&self,
operation_id: &str,
vault_path: &std::path::Path,
) -> Result<RollbackPreview> {
let engine = RollbackEngine::new(self.audit_log.clone(), self.snapshot_store.clone());
engine.preview(operation_id, vault_path).await
}
pub async fn rollback_execute(
&self,
operation_id: &str,
vault_path: &std::path::Path,
) -> Result<RollbackResult> {
let engine = RollbackEngine::new(self.audit_log.clone(), self.snapshot_store.clone());
engine.execute(operation_id, vault_path).await
}
pub fn snapshot_store(&self) -> &SnapshotStore {
&self.snapshot_store
}
pub fn audit_log(&self) -> &AuditLog {
&self.audit_log
}
}