#!/bin/bash
SUNO="/root/.openclaw/workspace/music-pipeline3000/skills/suno/suno.sh"
BASE="/tmp/music-pipeline/batch"

for d in "$BASE"/*/; do
  name=$(basename "$d")
  [ ! -f "$d/step2.json" ] && continue
  [ -f "$d/step3_suno.txt" ] && [ -s "$d/step3_suno.txt" ] && echo "⏭️  $name: already done" && continue
  
  echo ""
  echo "=========================================="
  echo "[Step 3] Suno: $name"
  echo "=========================================="
  
  PROMPT=$(python3 -c "import json; print(json.load(open('$d/step2.json'))['prompt'])")
  LYRICS=$(python3 -c "import json; print(json.load(open('$d/step2.json'))['lyrics'])")
  
  bash "$SUNO" custom "$PROMPT" "$LYRICS" > "$d/step3_suno.txt" 2>&1
  
  if grep -q "MP3:" "$d/step3_suno.txt"; then
    echo "✅ $name: Suno OK"
  else
    echo "❌ $name: Suno FAILED"
  fi
  
  sleep 3
done

echo ""
echo "=========================================="
echo "ALL SUNO DONE"
echo "=========================================="
