"""Testes do módulo writer."""

from pathlib import Path

from tecjustica_ocr.engine import PageResult, PdfResult
from tecjustica_ocr.writer import write_text_markdown


def test_write_text_markdown(tmp_path: Path):
    result = PdfResult(
        pdf_path=Path("teste.pdf"),
        pages=[
            PageResult(page_num=1, texts=["Linha 1", "Linha 2"], scores=[0.95, 0.88]),
            PageResult(page_num=2, texts=["Linha 3"], scores=[0.92]),
        ],
        num_pages=2,
    )

    md_path = write_text_markdown(result, tmp_path)

    assert md_path.exists()
    assert md_path.name == "teste.md"

    content = md_path.read_text()
    assert "# teste.pdf" in content
    assert "Página 1" in content
    assert "Linha 1" in content
    assert "Linha 3" in content
    assert "Textos extraídos**: 3" in content


def test_write_empty_pages(tmp_path: Path):
    result = PdfResult(
        pdf_path=Path("vazio.pdf"),
        pages=[PageResult(page_num=1, texts=[], scores=[])],
        num_pages=1,
    )

    md_path = write_text_markdown(result, tmp_path)
    content = md_path.read_text()
    assert "sem texto detectado" in content
