"""Tests para pdf_add_table."""

import sys
import os

sys.path.insert(0, os.path.dirname(__file__))
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "..", "python", "types", "infra"))

from pdf_create import pdf_create
from pdf_add_page import pdf_add_page
from pdf_add_table import pdf_add_table
from pdf_save import pdf_save


def test_tabla_con_headers_y_datos():
    doc = pdf_create()
    doc = pdf_add_page(doc)
    headers = ["Dominio", "Funciones", "Tipos"]
    rows = [
        ["core", "45", "12"],
        ["infra", "38", "8"],
        ["finance", "22", "6"],
    ]
    doc = pdf_add_table(doc, headers, rows)
    pdf_bytes = pdf_save(doc)
    assert pdf_bytes[:4] == b"%PDF"
    assert len(pdf_bytes) > 200


def test_tabla_con_col_widths_personalizados():
    doc = pdf_create()
    doc = pdf_add_page(doc)
    headers = ["Nombre", "Valor"]
    rows = [["alpha", "100"], ["beta", "200"]]
    doc = pdf_add_table(doc, headers, rows, col_widths=[100.0, 70.0])
    pdf_bytes = pdf_save(doc)
    assert pdf_bytes[:4] == b"%PDF"


def test_tabla_sin_borde():
    doc = pdf_create()
    doc = pdf_add_page(doc)
    headers = ["A", "B"]
    rows = [["1", "2"]]
    doc = pdf_add_table(doc, headers, rows, border=0)
    pdf_bytes = pdf_save(doc)
    assert pdf_bytes[:4] == b"%PDF"
