#!/bin/bash
# =============================================
#  ⚔️  AYN Antivirus — Dashboard Launcher
# =============================================
set -e

cd "$(dirname "$0")"

# Install deps if needed
if ! python3 -c "import aiohttp" 2>/dev/null; then
    echo "[*] Installing dependencies..."
    pip3 install -e . 2>&1 | tail -3
fi

# Create data dirs
mkdir -p /var/lib/ayn-antivirus /var/log/ayn-antivirus 2>/dev/null || true

# Get server IP
SERVER_IP=$(hostname -I 2>/dev/null | awk '{print $1}' || echo "0.0.0.0")

echo ""
echo "  ╔══════════════════════════════════════════╗"
echo "  ║  ⚔️  AYN ANTIVIRUS DASHBOARD             ║"
echo "  ╠══════════════════════════════════════════╣"
echo "  ║  🌐 http://${SERVER_IP}:7777              "
echo "  ║  🔑 API key shown below on first start   ║"
echo "  ║  Press Ctrl+C to stop                    ║"
echo "  ╚══════════════════════════════════════════╝"
echo ""

exec python3 -c "
from ayn_antivirus.config import Config
from ayn_antivirus.dashboard.server import DashboardServer
config = Config()
config.dashboard_host = '0.0.0.0'
config.dashboard_port = 7777
server = DashboardServer(config)
server.run()
"
