use pdfmake_rust::{CanvasShape, Document, DocumentNode, PdfMake};

#[test]
fn canvas_smoke_renders_without_error() {
    let doc = Document::builder()
        .content(DocumentNode::canvas(vec![
            CanvasShape::Rect {
                x: 50.0,
                y: 50.0,
                w: 200.0,
                h: 100.0,
                color: Some("#3498db".into()),
                line_color: None,
                line_width: None,
                fill_opacity: None,
                stroke_opacity: None,
            },
        ]))
        .build();

    let pdf = PdfMake::new().render(&doc).unwrap();
    assert!(pdf.starts_with(b"%PDF-1.4"));
    assert!(String::from_utf8_lossy(&pdf).contains("%%EOF"));
    assert!(pdf.len() > 100);
}

#[test]
fn canvas_with_opacity_renders() {
    let doc = Document::builder()
        .content(DocumentNode::canvas(vec![
            CanvasShape::Rect {
                x: 50.0,
                y: 50.0,
                w: 200.0,
                h: 100.0,
                color: Some("#e74c3c".into()),
                line_color: None,
                line_width: None,
                fill_opacity: Some(0.5),
                stroke_opacity: None,
            },
            CanvasShape::Rect {
                x: 100.0,
                y: 200.0,
                w: 150.0,
                h: 80.0,
                color: Some("#2ecc71".into()),
                line_color: Some("#000000".into()),
                line_width: Some(1.5),
                fill_opacity: Some(0.3),
                stroke_opacity: Some(0.8),
            },
        ]))
        .build();

    let pdf = PdfMake::new().render(&doc).unwrap();
    assert!(pdf.starts_with(b"%PDF-1.4"));
    assert!(String::from_utf8_lossy(&pdf).contains("%%EOF"));
    assert!(pdf.len() > 100);
}

#[test]
fn canvas_mixed_shapes_render() {
    let doc = Document::builder()
        .content(DocumentNode::canvas(vec![
            CanvasShape::Rect {
                x: 10.0,
                y: 10.0,
                w: 100.0,
                h: 50.0,
                color: Some("#ff0000".into()),
                line_color: None,
                line_width: None,
                fill_opacity: None,
                stroke_opacity: None,
            },
            CanvasShape::Ellipse {
                x: 200.0,
                y: 200.0,
                r1: 40.0,
                r2: 30.0,
                color: Some("#00ff00".into()),
                line_color: None,
                line_width: None,
            },
            CanvasShape::Line {
                x1: 0.0,
                y1: 0.0,
                x2: 300.0,
                y2: 400.0,
                line_color: Some("#0000ff".into()),
                line_width: Some(2.0),
            },
        ]))
        .build();

    let pdf = PdfMake::new().render(&doc).unwrap();
    assert!(pdf.starts_with(b"%PDF-1.4"));
    assert!(String::from_utf8_lossy(&pdf).contains("%%EOF"));
}

#[test]
fn canvas_with_full_opacity_is_noop() {
    let doc = Document::builder()
        .content(DocumentNode::canvas(vec![
            CanvasShape::Rect {
                x: 10.0,
                y: 10.0,
                w: 100.0,
                h: 50.0,
                color: Some("#ff0000".into()),
                line_color: None,
                line_width: None,
                fill_opacity: Some(1.0),
                stroke_opacity: Some(1.0),
            },
        ]))
        .build();

    let pdf = PdfMake::new().render(&doc).unwrap();
    assert!(pdf.starts_with(b"%PDF-1.4"));
    assert!(pdf.len() > 100);
}
