use codewhale_protocol::ids::ThreadId;
use codewhale_state::StateStore;
#[derive(Debug, Clone)]
pub struct ThreadStore {
inner: StateStore,
root: std::path::PathBuf,
}
impl ThreadStore {
#[must_use]
pub fn new(inner: StateStore, root: std::path::PathBuf) -> Self {
Self { inner, root }
}
#[must_use]
pub fn state(&self) -> &StateStore {
&self.inner
}
#[must_use]
pub fn root(&self) -> &std::path::Path {
&self.root
}
pub fn thread_exists(&self, id: &ThreadId) -> anyhow::Result<bool> {
Ok(self.inner.get_thread(id.as_str())?.is_some())
}
}
#[cfg(test)]
mod tests {
use super::*;
use tempfile::tempdir;
#[test]
fn store_wraps_state() {
let dir = tempdir().unwrap();
let state = StateStore::open(Some(dir.path().join("state.db"))).unwrap();
let store = ThreadStore::new(state, dir.path().to_path_buf());
assert!(!store.thread_exists(&ThreadId::new()).unwrap());
}
}