#!/usr/bin/env bash
set -euo pipefail
if [ "$#" -lt 2 ]; then
  echo "usage: $0 <file> [more_files ...] <class_name> [assignment_name]" >&2
  exit 1
fi

ARGS=("$@")
COUNT=$#
if [ "$COUNT" -eq 2 ]; then
  FILES=("${ARGS[0]}")
  CLASS_NAME="${ARGS[1]}"
  ASSIGNMENT_NAME="Sample Assignment"
elif [ "$COUNT" -eq 3 ]; then
  FILES=("${ARGS[0]}")
  CLASS_NAME="${ARGS[1]}"
  ASSIGNMENT_NAME="${ARGS[2]}"
else
  FILES=("${ARGS[@]:0:$COUNT-2}")
  CLASS_NAME="${ARGS[$COUNT-2]}"
  ASSIGNMENT_NAME="${ARGS[$COUNT-1]}"
fi

TARGET="${N8N_BASE_URL:-https://n8n.example.com}${SCHOOLHOUSE_N8N_ASSIGNMENT_WEBHOOK:-/webhook/school/intake/upload}"

echo "Dry-run assignment handoff preview"
echo "Target: $TARGET"
echo "Command:"
echo "curl -X POST \"$TARGET\" \\"
for file in "${FILES[@]}"; do
  echo "  -F \"document=@$file\" \\"
done
echo "  -F \"class_name=$CLASS_NAME\" \\"
echo "  -F \"assignment_name=$ASSIGNMENT_NAME\" \\"
echo "  -F \"submission_kind=assignment_turn_in\" \\"
echo "  -F \"source=doris-schoolhouse\""
