#![cfg(all(feature = "image", feature = "svg", feature = "qr"))]

use pdfmake_rust::{Document, DocumentNode, ImageNode, PdfMake, QrNode, SvgNode};

#[test]
fn render_document_with_text_image_qr_and_svg() {
    let document = Document::builder()
        .content(DocumentNode::text("before"))
        .content(DocumentNode::image(ImageNode::bytes(minimal_jpeg_1x1()).width(24.0)))
        .content(DocumentNode::qr(QrNode::new("hello").fit(48.0)))
        .content(DocumentNode::svg(SvgNode::new(r#"<svg width="20" height="10"><rect width="20" height="10"/></svg>"#)))
        .content(DocumentNode::text("after"))
        .build();

    let pdf = PdfMake::new().render(&document).unwrap();
    let text = String::from_utf8_lossy(&pdf);
    assert!(text.starts_with("%PDF-1.4"));
    assert!(text.contains("/XObject"));
    assert!(text.contains("/Subtype /Image"));
    assert!(text.contains("xref"));
}

fn minimal_jpeg_1x1() -> Vec<u8> {
    vec![
        0xFF, 0xD8,
        0xFF, 0xC0, 0x00, 0x0B, 0x08, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,
        0xFF, 0xD9,
    ]
}
