#!/usr/bin/env bash
# DataAutomation.ai Digital Employee (DADE) - macOS Runner Launcher
set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd "$DIR"

echo "======================================================================"
echo "   DataAutomation.ai Digital Employee (DADE) - Workstation Runner"
echo "======================================================================"
echo ""

if ! command -v python3 &> /dev/null; then
    echo "[!] Python 3 is not installed on this Mac."
    echo "Please install Python from https://www.python.org/downloads/ or via Homebrew:"
    echo "   brew install python"
    read -p "Press Enter to exit..."
    exit 1
fi

echo "[*] Python 3 detected: $(python3 --version)"
echo "[*] Ensuring required modules are installed..."
python3 -m pip install websockets pillow uvicorn fastapi pydantic httpx --quiet 2>/dev/null || true

TARGET_RUNNER="dade-runner.py"
if [ ! -f "dade-runner.py" ] && [ -f "runner.py" ]; then
    TARGET_RUNNER="runner.py"
fi

echo "[*] Launching DADE runner on port 8089..."
echo "[*] Move cursor to top-left corner (0,0) or press Ctrl+C to halt at any time."
echo "======================================================================"
echo ""

python3 "$TARGET_RUNNER" --port 8089
