use std::fmt;

#[derive(Debug)]
pub enum MigrationError {
    AlreadyApplied(String),
    NotFound(String),
    Sql(String),
    MissingDown(String),
}

impl fmt::Display for MigrationError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            MigrationError::AlreadyApplied(id) => write!(f, "migration '{}' already applied", id),
            MigrationError::NotFound(id) => write!(f, "migration '{}' not found", id),
            MigrationError::Sql(s) => write!(f, "sql error: {}", s),
            MigrationError::MissingDown(id) => write!(f, "migration '{}' has no down sql", id),
        }
    }
}

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