use thiserror::Error;

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

#[derive(Debug, Error)]
pub enum PdfMakeError {
    #[error("document content is empty")]
    EmptyDocument,
    #[error("invalid page size: {0}")]
    InvalidPageSize(String),
    #[error("invalid margin definition")]
    InvalidMargin,
    #[error("unknown style: {0}")]
    UnknownStyle(String),
    #[error("render error: {0}")]
    Render(String),
    #[error("font family not registered: {0}")]
    UnknownFontFamily(String),
    #[error("failed to read font '{family}' at '{path}': {source}")]
    FontRead { family: String, path: String, source: std::io::Error },
    #[error("failed to parse font '{family}'")]
    FontParse { family: String },
    #[error("font '{family}' does not contain glyph for character '{ch}'{hint}")]
    MissingGlyph { family: String, ch: char, hint: String },
    #[error("I/O error while writing PDF data: {0}")]
    PdfWrite(#[from] std::io::Error),
    #[error("failed to read image at '{path}': {source}")]
    ImageRead { path: String, source: std::io::Error },
    #[error("unsupported image format")]
    UnsupportedImageFormat,
    #[error("invalid image dimensions")]
    InvalidImageDimensions,
    #[error("QR content is empty")]
    InvalidQrContent,
    #[error("failed to encode QR content")]
    QrEncode,
    #[error("failed to parse SVG: {0}")]
    SvgParse(String),
    #[error("unsupported SVG element: {0}")]
    UnsupportedSvgElement(String),
    #[error("invalid base64 image data: {0}")]
    InvalidBase64(String),
}