#[derive(Debug)]
pub enum MosaicError {
    Io(std::io::Error),
    Serialize(String),
    Deserialize(String),
}

impl std::fmt::Display for MosaicError {
    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Io(error) => write!(formatter, "IO error: {error}"),
            Self::Serialize(message) => write!(formatter, "Serialization error: {message}"),
            Self::Deserialize(message) => write!(formatter, "Deserialization error: {message}"),
        }
    }
}

impl std::error::Error for MosaicError {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Self::Io(error) => Some(error),
            _ => None,
        }
    }
}

impl From<std::io::Error> for MosaicError {
    fn from(error: std::io::Error) -> Self {
        Self::Io(error)
    }
}
