use libgrite_core::{types::event::Event, types::ids::ActorId, GriteError, GriteStore};
use libgrite_git::{GitError, WalManager};
pub struct InsertResult {
pub wal_head: Option<String>,
}
pub fn insert_and_append(
store: &GriteStore,
wal: &WalManager,
actor: &ActorId,
event: &Event,
) -> Result<InsertResult, GriteError> {
store.insert_event(event)?;
store.flush()?;
let wal_head = match wal.append(actor, std::slice::from_ref(event)) {
Ok(oid) => Some(oid.to_string()),
Err(e) => {
eprintln!("Warning: Failed to append to WAL: {}", e);
None
}
};
Ok(InsertResult { wal_head })
}
#[allow(dead_code)]
pub fn append_to_wal(
wal: &WalManager,
actor: &ActorId,
events: &[Event],
) -> Result<Option<String>, GitError> {
if events.is_empty() {
return Ok(None);
}
let oid = wal.append(actor, events)?;
Ok(Some(oid.to_string()))
}