#!/bin/bash
set -e

OUTDIR="/var/www/sneakerpicks/public/rembg-test"
mkdir -p "$OUTDIR"

MODELS="u2net isnet-general-use birefnet-general u2net_human_seg"

# Product IDs and image URLs from DB query
declare -A IMAGES
IMAGES[1246330]="https://www.schuurman-schoenen.nl/on/demandware.static/-/Sites-product-master/default/dw7b0a2f18/regular/Abeba/6000064784_70_0002.jpg"
IMAGES[1245643]="https://www.schuurman-schoenen.nl/on/demandware.static/-/Sites-product-master/default/dw5c6986b3/regular/PS_POELMAN/6000060418_15_0002.jpg"
IMAGES[1261459]="https://img01.ztat.net/article/spp-media-p1/6f40396965584bd7b64fe4af097b9f1b/3ec5dc24324b49f2b189ff636e669ec8.jpg?imwidth=762"
IMAGES[1230168]="https://www.vanarendonk.nl/img/1200/1500/resize/catalog/product/5/8/58.19.14_1.jpg"
IMAGES[1264728]="https://img01.ztat.net/article/spp-media-p1/9b665ad9a0554d53b8b1e5bfc0543cd7/573060858dec476bb19326178b1c758f.jpg?imwidth=762"
IMAGES[1260593]="https://img01.ztat.net/article/spp-media-p1/67d7e0bea05445f88ebf8f288cebd037/1731cbb59a4242b4a290e9a0a164cedf.jpg?imwidth=762"
IMAGES[1264643]="https://img01.ztat.net/article/spp-media-p1/f24eb5840acb317c82b118adda94a6e8/b59124e956ed4a46bedea2f4a1750111.jpg?imwidth=762"
IMAGES[1256357]="https://img01.ztat.net/article/spp-media-p1/7b97d108d0d543c891a8a5d30c4e5cc2/76f15403891f4b968922a31a0133957c.jpg?imwidth=762"
IMAGES[1251323]="https://img01.ztat.net/article/spp-media-p1/a06e0985e2544fa393e8de5ae650bfa2/93a5ca99db48407a8ad43b61b28f9f0a.jpg?imwidth=762"
IMAGES[1231306]="https://www.vanarendonk.nl/img/1200/1500/resize/catalog/product/1/2/129.15.2_1.jpg"

for PID in "${!IMAGES[@]}"; do
  URL="${IMAGES[$PID]}"
  INPUT="$OUTDIR/${PID}_original.jpg"
  
  echo "=== Processing product $PID ==="
  
  # Download original
  if [ ! -f "$INPUT" ]; then
    echo "Downloading $URL"
    curl -sL -o "$INPUT" "$URL" || { echo "FAILED to download $PID"; continue; }
  fi
  
  # Run each model
  for MODEL in $MODELS; do
    OUTPUT="$OUTDIR/${PID}_${MODEL}.png"
    if [ -f "$OUTPUT" ]; then
      echo "  $MODEL: already exists, skipping"
      continue
    fi
    echo "  Running $MODEL..."
    rembg i -m "$MODEL" "$INPUT" "$OUTPUT" 2>&1 || echo "  FAILED: $MODEL on $PID"
  done
done

echo "=== DONE ==="
ls -la "$OUTDIR"
