#!/bin/sh
set -e

echo "=== Puzzle Generator Container Starting ==="
echo "Time: $(date)"
echo "Output directory: ${OUT_DIR}"
echo "Puzzles per day: ${PUZZLES_PER_DAY}"
echo ""

# Ensure output directory exists
mkdir -p "${OUT_DIR}/puzzles"

# Generate initial puzzle on startup (optional)
if [ "${GENERATE_ON_START}" = "true" ]; then
    echo "Generating initial puzzles..."
    START_CLASS=${START_CLASS:-puzzle.Main}
    echo "Running ${START_CLASS}..."
    java -cp /app/target/postgresql-42.7.8.jar:/app/target ${START_CLASS}
    echo ""
fi

# Start cron scheduler
echo "Starting cron scheduler..."
exec /usr/local/bin/supercronic /app/crontab
