use crate::{
    Document, DocumentNode, Margins, PageBreakMode, PageSize, Style, TableCell, TableNode,
    TableWidth, TextNode,
};

pub fn build_text_10k_document(text_blocks: usize) -> Document {
    let mut lines = String::new();
    for i in 0..text_blocks {
        if i > 0 {
            lines.push(' ');
        }
        lines.push_str("benchmark text");
    }

    Document::builder()
        .page_size(PageSize::a4())
        .page_margins(Margins::all(40.0))
        .content(DocumentNode::Text(TextNode::new(lines)))
        .build()
}

pub fn build_table_1000_document(row_count: usize) -> Document {
    let mut body = Vec::with_capacity(row_count + 1);
    body.push(vec![
        TableCell::text("ID").style(Style::new().bold(true)),
        TableCell::text("Label").style(Style::new().bold(true)),
        TableCell::text("Value").style(Style::new().bold(true)),
    ]);

    for row in 0..row_count {
        body.push(vec![
            TableCell::text(format!("{}", row + 1)),
            TableCell::text(format!("Row {}", row + 1)),
            TableCell::text(format!("Value {}", row + 1)),
        ]);
    }

    Document::builder()
        .page_size(PageSize::a4())
        .page_margins(Margins::all(40.0))
        .content(DocumentNode::Table(
            TableNode::new(body).widths(vec![
                TableWidth::Fixed(50.0),
                TableWidth::Star,
                TableWidth::Fixed(90.0),
            ]),
        ))
        .build()
}

pub fn build_pages_100_document(page_count: usize) -> Document {
    let mut content = Vec::with_capacity(page_count);
    for i in 0..page_count {
        let mut node = TextNode::new(format!("Page {} benchmark content", i + 1))
            .inline_style(Style::new().font_size(14.0));

        if i > 0 {
            node = node.page_break(PageBreakMode::Before);
        }

        content.push(DocumentNode::Text(node));
    }

    let mut document = Document::builder()
        .page_size(PageSize::a4())
        .page_margins(Margins::all(40.0))
        .build();
    document.content = content;
    document
}
