use std::time::SystemTime;
use anyhow::Result;
use crate::types::{
AheadBehind, BlameEntry, BranchInfo, CommitId, CommitInfo, DiffSummary, SortOrder,
StashEntry, StatusDigest, SubmoduleInfo, TagInfo, WorktreeInfo, WorktreeStatus,
};
pub trait VcsBackend: Send + Sync {
fn status_digest(&self) -> Result<StatusDigest>;
fn local_branches(&self) -> Result<Vec<BranchInfo>>;
fn remote_branches(&self) -> Result<Vec<BranchInfo>>;
fn list_commits(&self) -> Result<Vec<CommitInfo>>;
fn list_commits_sorted(&self, order: SortOrder) -> Result<Vec<CommitInfo>>;
fn log_since(&self, since: SystemTime, until: SystemTime) -> Result<Vec<CommitInfo>>;
fn find_commit(&self, id: &CommitId) -> Result<CommitInfo>;
fn list_tags(&self) -> Result<Vec<TagInfo>>;
fn list_tags_sorted(&self, order: SortOrder) -> Result<Vec<TagInfo>>;
fn diff(&self, from: &CommitId, to: &CommitId) -> Result<DiffSummary>;
fn is_dirty(&self) -> Result<bool>;
fn merge_base(&self, a: &CommitId, b: &CommitId) -> Result<Option<CommitId>>;
fn is_ancestor(&self, candidate: &CommitId, descendant: &CommitId) -> Result<bool>;
fn blame(&self, path: &std::path::Path) -> Result<Vec<BlameEntry>>;
fn worktree_status(&self) -> Result<WorktreeStatus>;
fn file_at_commit(&self, path: &std::path::Path, commit_id: &CommitId) -> Result<Vec<u8>>;
fn ahead_behind(&self, local: &CommitId, upstream: &CommitId) -> Result<AheadBehind>;
fn remote_url(&self, _name: &str) -> Option<String> {
None
}
fn submodules(&self) -> Result<Vec<SubmoduleInfo>> {
Ok(Vec::new())
}
fn stash_entries(&self) -> Result<Vec<StashEntry>> {
Ok(Vec::new())
}
fn worktrees(&self) -> Result<Vec<WorktreeInfo>> {
Ok(Vec::new())
}
fn create_tag(&self, name: &str) -> Result<()> {
anyhow::bail!("backend does not support lightweight tag creation: {name:?}")
}
fn create_annotated_tag(&self, name: &str, _message: &str) -> Result<()> {
anyhow::bail!("backend does not support annotated tag creation: {name:?}")
}
fn delete_tag(&self, name: &str) -> Result<()> {
anyhow::bail!("backend does not support tag deletion: {name:?}")
}
fn branch_ahead_behind(&self, branch: &str) -> Result<Option<AheadBehind>> {
anyhow::bail!("backend does not support branch_ahead_behind({branch:?})")
}
}