use super::MemoryConfigStore;
use crate::storage::Error;
use pbbson::Model;

pub async fn perform<B: Clone + Send + Sync + ToString>(
    this: &MemoryConfigStore<B>,
    bucket: B,
    id: &str,
) -> Result<Model, Error> {
    let doc_holder = this.doc_holder(&bucket)?;
    let docs = doc_holder
        .docs
        .lock()
        .map_err(|e| Error::failed_precondition(e.to_string()))?;
    let model = match docs.get(id) {
        None => return Err(Error::not_found("No such record")),
        Some(model) => model,
    };
    Ok(model.clone())
}
