#!/bin/bash

# --- INFRASTRUCTURE RESET: APPS AND DOCKER ENGINE ---
# Objective: Wipe the virtual medical devices but keep the lab files.

echo "--- STARTING INFRASTRUCTURE PURGE (KEEPING FILES) ---"

# 1. DEEP CLEAN DOCKER (Requires sudo for permissions)
if command -v docker &> /dev/null; then
    echo "Stopping all running lab containers..."
    sudo docker ps -q | xargs -r sudo docker stop

    echo "Removing all containers and associated volumes..."
    sudo docker ps -a -q | xargs -r sudo docker rm -v

    echo "Deleting Docker images (Orthanc, Sysmex-Sim, etc.)..."
    sudo docker images -q | xargs -r sudo docker rmi -f

    echo "Pruning all unused Docker networks and system cache..."
    sudo docker network prune -f
    sudo docker system prune -a --volumes -f
else
    echo "Docker not detected. Skipping container purge."
fi

# 2. UNINSTALL LINUX TOOLS
echo "Uninstalling scanning and utility tools..."
if command -v dnf &> /dev/null; then
    sudo dnf remove -y nmap curl jq
elif command -v apt-get &> /dev/null; then
    sudo apt-get purge -y nmap curl jq
    sudo apt-get autoremove -y
fi

# 3. NOTIFICATION
echo "------------------------------------------"
echo "INFRASTRUCTURE RESET COMPLETE"
echo "NOTE: Lab PDFs, Excel files, and scripts were NOT deleted."
echo "Location: $HOME"
echo "------------------------------------------"