use std::fmt;

#[derive(Debug, Clone)]
pub enum Error {
    Msg(String),
    XlsxError(String),
    IoError(String),
    PolarsError(String),
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Error::Msg(msg) => write!(f, "XlsxToCsvError: {msg}"),
            Error::XlsxError(msg) => write!(f, "XlsxError: {msg}"),
            Error::IoError(msg) => write!(f, "IoError: {msg}"),
            Error::PolarsError(msg) => write!(f, "PolarsError: {msg}"),
        }
    }
}

impl From<umya_spreadsheet::XlsxError> for Error {
    fn from(value: umya_spreadsheet::XlsxError) -> Self {
        Error::XlsxError(value.to_string())
    }
}

impl From<&str> for Error {
    fn from(value: &str) -> Self {
        Error::Msg(value.to_string())
    }
}

impl From<String> for Error {
    fn from(value: String) -> Self {
        Error::Msg(value)
    }
}

impl From<std::io::Error> for Error {
    fn from(value: std::io::Error) -> Self {
        Error::IoError(value.to_string())
    }
}
