use std::io;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum GenerationError {
#[error("Invalid password length")]
InvalidLength,
#[error("Invalid timeout value")]
InvalidTimeout,
#[error("Password generation failed")]
GenerationFailed,
#[error("No character set selected")]
NoCharacterSet,
#[error("Translation missing: {0}")]
TranslationMissing(String),
#[error("IO error: {0}")]
IoError(#[from] io::Error),
#[error("Unsupported language")]
UnsupportedLanguage,
#[error("Resource parse error")]
ResourceParseError,
#[error("Interaction cancelled or invalid input.")]
InvalidInput,
#[error("Strict target unmet within time budget")]
StrictTargetUnmet,
#[error("Input failure: {0}")]
InputFailure(String),
#[error("Failed to gather entropy from the operating system.")]
EntropyError(#[from] getrandom::Error),
#[error("Random generation failed: {0}")]
RngFailure(String),
#[error("Password strength evaluation failed: {0}")]
StrengthEvaluationError(String),
#[error("Infeasible character set: {0}")]
InvalidCharset(String),
}
pub fn exit_code_for_error(err: &GenerationError) -> i32 {
match err {
GenerationError::StrictTargetUnmet => 3,
GenerationError::InvalidCharset(_) => 2,
_ => 1,
}
}
pub type Result<T> = std::result::Result<T, GenerationError>;