use anyhow::{anyhow, Result};
use crate::{IgnoreStore, Operation, ProjectId, ProjectInfo, ProjectPath};
pub trait Repository {
fn ignore_store_mut(&mut self) -> &mut dyn IgnoreStore;
fn ignore_store(&self) -> &dyn IgnoreStore;
fn new_project(&mut self, project_path: &ProjectPath) -> Result<ProjectId>;
fn project_exists(&mut self, project_path: &ProjectPath) -> Result<bool>;
fn remove_project(&mut self, project_id: ProjectId) -> Result<()>;
fn get_project_id(&mut self, project_path: &ProjectPath) -> Result<ProjectId>;
fn projects(&mut self) -> Result<Vec<ProjectInfo>>;
fn insert_operation(&mut self, operation: &Operation) -> Result<()>;
fn pop_last_operation(&mut self) -> Result<Option<Operation>>;
fn undo(&mut self) -> Result<()> {
let last_operation = self.pop_last_operation()?;
let mut last_operation = last_operation.ok_or_else(|| anyhow!("Nothing to undo"))?;
last_operation.undo(self.ignore_store_mut())
}
}