#!/usr/bin/env python3
"""Simulation de l'appel GUI pour identifier l'erreur."""

from pathlib import Path
import sys

# Ajouter le répertoire parent au path
sys.path.insert(0, str(Path(__file__).parent.parent))

import anonymizer_core_refactored_onnx as core
from config_defaults import RUNTIME_DICTIONARIES_CONFIG_PATH

# Simuler exactement ce que fait le GUI
test_pdf = Path("/tmp/test_gui_pdfs/001_simple_unknown_BACTERIO_23018396.pdf")
out_dir = Path("/tmp/test_gui_pdfs/anonymise")

if not test_pdf.exists():
    print(f"❌ PDF non trouvé: {test_pdf}")
    sys.exit(1)

print(f"Test avec: {test_pdf}")
print(f"Sortie dans: {out_dir}")

try:
    # Appel identique au GUI (lignes 754-764)
    outputs = core.process_pdf(
        pdf_path=test_pdf,
        out_dir=out_dir,
        make_vector_redaction=False,
        also_make_raster_burn=True,
        config_path=RUNTIME_DICTIONARIES_CONFIG_PATH,
        use_hf=False,
        ner_manager=None,
        ner_thresholds=None,
        ogc_label=None,
        vlm_manager=None,
    )
    print(f"✅ Succès!")
    for k, v in outputs.items():
        print(f"  - {k}: {v}")
except Exception as e:
    print(f"❌ Erreur: {e}")
    import traceback
    traceback.print_exc()
    sys.exit(1)
