#!/usr/bin/env bash
set -e

echo "=================================================="
echo "  🚀 TO-Agent v0.1 Alpha 1-Klick Einzel-Installer"
echo "=================================================="

TARGET_DIR="$HOME/to-agent"
mkdir -p "$TARGET_DIR"
cd "$TARGET_DIR"

echo "-> Lade TO-Agent v0.1 Hauptsystem herunter..."
if command -v curl >/dev/null 2>&1; then
    curl -fsSL "https://to-chat.net/downloads/to-agent-v0.1.zip" -o to-agent-v0.1.zip
elif command -v wget >/dev/null 2>&1; then
    wget -q "https://to-chat.net/downloads/to-agent-v0.1.zip" -O to-agent-v0.1.zip
else
    echo "Fehler: Weder curl noch wget gefunden."
    exit 1
fi

echo "-> Entpacke TO-Agent..."
if command -v unzip >/dev/null 2>&1; then
    unzip -o -q to-agent-v0.1.zip
else
    python3 -c "import zipfile; zipfile.ZipFile('to-agent-v0.1.zip').extractall('.')"
fi

cd to-agenten-system

echo "-> Richte Abhängigkeiten ein und starte TO-Agent..."
chmod +x install.sh starten.sh 2>/dev/null || true

if [ -f "install.sh" ]; then
    ./install.sh
else
    ./starten.sh
fi
