#!/usr/bin/env bash
# Dump raw camelot output under the current version (project venv) and an
# older baseline (ephemeral uv env) across all docs. Writes v2_<name>.json
# (current) and v1_<name>.json (baseline) into $REVIEW_DIR.
#
# Env:
#   REVIEW_DIR   output dir for the JSON dumps (default .camelot-eval)
#   V2_EXTRA     extra read_pdf kwargs for the current run only (e.g. line_scale=40)
#   V1_CAMELOT   baseline camelot version (default 1.0.9)
set -u
cd "$(git rev-parse --show-toplevel)"
SCRIPTS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REVIEW_DIR="${REVIEW_DIR:-.camelot-eval}"
mkdir -p "$REVIEW_DIR"
source .venv/bin/activate

V2_EXTRA="${V2_EXTRA:-}"
V1_CAMELOT="${V1_CAMELOT:-1.0.9}"

for pdf in documents/*.pdf; do
  name=$(basename "$pdf" .pdf)
  echo "=== $name ==="
  python "$SCRIPTS/raw_extract.py" "$pdf" "$REVIEW_DIR/v2_${name}.json" $V2_EXTRA 2>>"$REVIEW_DIR/v2_errors.log"
  uv run --no-project --quiet --with "camelot-py==${V1_CAMELOT}" --with 'opencv-python-headless' \
    python "$SCRIPTS/raw_extract.py" "$pdf" "$REVIEW_DIR/v1_${name}.json" 2>>"$REVIEW_DIR/v1_errors.log"
done
echo "ALL DONE"
