#!/bin/bash
# Helper script: Queue task, wait, and display results
# Usage: ./auto-wait-and-check.sh <task-file>

TASK_FILE=$1
TASK_NAME=$(basename "$TASK_FILE" .sh)

# Queue the task
cp "$TASK_FILE" automation/queue/
chmod +x "automation/queue/$TASK_NAME.sh"

# Wait for execution (daemon polls every 10s, add buffer)
echo "Task queued: $TASK_NAME"
echo "Waiting for execution..."
sleep 20

# Display results
if [ -f "automation/results/${TASK_NAME}_result.txt" ]; then
    cat "automation/results/${TASK_NAME}_result.txt"
else
    echo "No results yet. Task may still be running or failed."
fi
