use crate::core::error::{ApiError, ConfigError, GitError, PromptError};
use crate::core::http::{HttpRequest, HttpResponse};
use crate::core::repo::RepoId;
pub trait Transport: Send + Sync {
fn execute(&self, req: HttpRequest) -> Result<HttpResponse, ApiError>;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Remote {
pub name: String,
pub repo: RepoId,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Commit {
pub sha: String,
pub title: String,
}
pub trait GitClient: Send + Sync {
fn current_branch(&self) -> Result<String, GitError>;
fn remotes(&self) -> Result<Vec<Remote>, GitError>;
fn push(&self, remote: &str, refspec: &str) -> Result<(), GitError>;
fn commits_between(&self, base: &str, head: &str) -> Result<Vec<Commit>, GitError>;
fn fetch(&self, remote: &str, refspec: &str) -> Result<(), GitError>;
fn merge_ff(&self, committish: &str) -> Result<(), GitError>;
fn checkout(&self, branch: &str) -> Result<(), GitError>;
fn add_remote(&self, name: &str, url: &str) -> Result<(), GitError>;
fn clone_repo(&self, url: &str, dir: Option<&str>) -> Result<(), GitError>;
fn config_set_global(&self, key: &str, value: &str) -> Result<(), GitError>;
fn config_add_global(&self, key: &str, value: &str) -> Result<(), GitError>;
}
pub trait Prompter: Send + Sync {
fn confirm(&self, message: &str, default: bool) -> Result<bool, PromptError>;
fn input(&self, message: &str, default: Option<&str>) -> Result<String, PromptError>;
fn password(&self, message: &str) -> Result<String, PromptError>;
fn select(&self, message: &str, options: &[String]) -> Result<usize, PromptError>;
fn editor(&self, message: &str, initial: &str) -> Result<String, PromptError>;
}
pub trait Browser: Send + Sync {
fn browse(&self, url: &str) -> Result<(), std::io::Error>;
}
pub trait ConfigProvider: Send + Sync {
fn get(&self, host: &str, key: &str) -> Option<String>;
fn set(&self, host: &str, key: &str, value: &str) -> Result<(), ConfigError>;
fn unset_host(&self, host: &str) -> Result<(), ConfigError>;
fn default_host(&self) -> String;
fn auth_token(&self, host: &str) -> Option<String>;
fn hosts(&self) -> Vec<String>;
fn save(&self) -> Result<(), ConfigError>;
}