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

#[test]
fn text_node_with_id_field() {
    let node = TextNode::new("Chapter 1").id("chapter1");
    assert_eq!(node.id, Some("chapter1".to_string()));
}

#[test]
fn text_node_with_page_reference_field() {
    let node = TextNode::new("See page").page_reference("chapter1");
    assert_eq!(node.page_reference, Some("chapter1".to_string()));
}

#[test]
fn document_with_page_reference_renders() {
    let doc = Document::builder()
        .content(DocumentNode::Text(TextNode::new("Chapter 1: Introduction").id("chapter1")))
        .content(DocumentNode::Text(TextNode::new("See page ").page_reference("chapter1")))
        .build();

    let result = PdfMake::new().render(&doc);
    assert!(result.is_ok());
}

#[test]
fn document_with_multiple_references_renders() {
    let doc = Document::builder()
        .content(DocumentNode::Text(TextNode::new("Chapter 1").id("ch1")))
        .content(DocumentNode::Text(TextNode::new("Chapter 2").id("ch2")))
        .content(DocumentNode::Text(TextNode::new("Go to page ").page_reference("ch1")))
        .content(DocumentNode::Text(TextNode::new("Go to page ").page_reference("ch2")))
        .build();

    let result = PdfMake::new().render(&doc);
    assert!(result.is_ok());
}

#[test]
fn document_with_reference_to_nonexistent_id_renders() {
    let doc = Document::builder()
        .content(DocumentNode::Text(TextNode::new("See page ").page_reference("nonexistent")))
        .build();

    let result = PdfMake::new().render(&doc);
    assert!(result.is_ok());
}

#[test]
fn document_with_id_in_multipage_renders() {
    let doc = Document::builder()
        .content(DocumentNode::text("First page content"))
        .content(DocumentNode::Text(TextNode::new("Second page content").id("page2")))
        .content(DocumentNode::text("More content to fill page"))
        .content(DocumentNode::Text(TextNode::new("See page ").page_reference("page2")))
        .build();

    let result = PdfMake::new().render(&doc);
    assert!(result.is_ok());
}
