use std::fmt;

#[derive(Debug)]
pub enum LabGeneticsError {
    NoInput,
    IoError(String),
    ParseError(String),
    CatalogError(String),
    ConfigError(String),
}

impl fmt::Display for LabGeneticsError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::NoInput => write!(f, "No input provided. Use a file, --genes, or --stdin"),
            Self::IoError(msg) => write!(f, "I/O error: {msg}"),
            Self::ParseError(msg) => write!(f, "Parse error: {msg}"),
            Self::CatalogError(msg) => write!(f, "Catalog error: {msg}"),
            Self::ConfigError(msg) => write!(f, "Config error: {msg}"),
        }
    }
}

impl std::error::Error for LabGeneticsError {}

impl LabGeneticsError {
    pub fn exit(&self) -> ! {
        match self {
            Self::NoInput | Self::ParseError(_) => std::process::exit(3),
            Self::ConfigError(_) | Self::CatalogError(_) => std::process::exit(2),
            Self::IoError(_) => std::process::exit(1),
        }
    }
}
