#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[error("HTML parse error: {0}")]
    HtmlParse(String),

    #[error("Layout error: {0}")]
    Layout(String),

    #[error("PDF generation error: {0}")]
    PdfGeneration(String),

    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),

    #[error("Asset error: {0}")]
    Asset(String),

    #[error("Template error: {0}")]
    Template(String),

    #[error("WOFF decode error: {0}")]
    WoffDecode(String),

    #[error("Unsupported font format: {0}")]
    UnsupportedFontFormat(String),

    #[error("{0}")]
    Other(String),
}

impl From<minijinja::Error> for Error {
    fn from(e: minijinja::Error) -> Self {
        Error::Template(e.to_string())
    }
}

pub type Result<T> = std::result::Result<T, Error>;

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_template_error_display() {
        let err = Error::Template("syntax error at line 3".into());
        assert!(err.to_string().contains("syntax error at line 3"));
    }
}
