#!/usr/bin/env bash
#
# Reset the Dezky local stack — destroys all data, restarts fresh.
# Useful when something is broken and you want to start over.
#

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
COMPOSE_DIR="$(cd "$SCRIPT_DIR/../infrastructure/docker-compose" && pwd)"

echo ""
echo "⚠️  WARNING: This will DESTROY ALL local data:"
echo "   - All databases"
echo "   - All file uploads"
echo "   - All Authentik configuration"
echo "   - All mail in Stalwart"
echo ""
read -p "Are you absolutely sure? Type 'yes' to confirm: " CONFIRM

if [[ "$CONFIRM" != "yes" ]]; then
    echo "Aborted."
    exit 0
fi

cd "$COMPOSE_DIR"

echo "Stopping all services..."
docker compose down -v

echo "Removing dangling volumes..."
docker volume prune -f --filter "label=com.docker.compose.project=dezky" 2>/dev/null || true

echo ""
echo "Reset complete. Run scripts/bootstrap.sh to start over."
