use miette::Diagnostic;
use thiserror::Error;
use crate::auth::AuthError;
use crate::config::ConfigError;
use crate::forge::ForgeError;
use crate::jj::JjError;
use crate::select::bookmark_gen::BookmarkGenError;
use crate::submit::SubmitError;
#[derive(Debug, Error, Diagnostic)]
pub enum StakkError {
#[error(transparent)]
#[diagnostic(transparent)]
Jj(#[from] JjError),
#[error(transparent)]
#[diagnostic(transparent)]
Forge(#[from] ForgeError),
#[error(transparent)]
#[diagnostic(transparent)]
Auth(#[from] AuthError),
#[error(transparent)]
#[diagnostic(transparent)]
Submit(#[from] SubmitError),
#[error(transparent)]
#[diagnostic(transparent)]
BookmarkGen(#[from] BookmarkGenError),
#[error(transparent)]
#[diagnostic(transparent)]
Config(#[from] ConfigError),
#[error("remote '{name}' is not a GitHub URL: {url}")]
#[diagnostic(
code(stakk::remote::not_github),
help("stakk only supports GitHub remotes (github.com URLs)")
)]
RemoteNotGithub { name: String, url: String },
#[error("remote '{name}' not found")]
#[diagnostic(
code(stakk::remote::not_found),
help("run `jj git remote list` to see available remotes")
)]
RemoteNotFound { name: String },
#[error("no GitHub remote found")]
#[diagnostic(
code(stakk::remote::no_github),
help("Make sure this repository has a GitHub remote configured")
)]
NoGithubRemote,
#[error("failed to load template '{path}': {reason}")]
#[diagnostic(
code(stakk::template::load_failed),
help("check that the file exists and is readable")
)]
TemplateLoadFailed { path: String, reason: String },
#[error("{0}")]
#[diagnostic(code(stakk::cli))]
Cli(#[from] clap::Error),
#[error("terminal I/O error: {0}")]
#[diagnostic(code(stakk::io))]
Io(#[from] std::io::Error),
#[error("interactive mode requires a terminal")]
#[diagnostic(
code(stakk::not_interactive),
help("Pass the bookmark name explicitly: stakk submit <BOOKMARK>")
)]
NotInteractive,
#[error("interactive selection cancelled")]
#[diagnostic(code(stakk::prompt_cancelled))]
#[expect(
dead_code,
reason = "available for callers that want to distinguish cancellation from success"
)]
PromptCancelled,
#[error("interrupted")]
#[diagnostic(code(stakk::interrupted))]
Interrupted,
}