#!/bin/bash

set -e
set -u
set -o pipefail

echo "INFO: Starting project cleanup script..."
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"

echo "WARNING: This will remove generated files and virtual environments."
read -r -p "Are you sure you want to continue? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
    echo "INFO: Cleaning up project..."

    # Remove virtual environments created by run_xxx.sh scripts
    echo "INFO: Removing .venv_test_runner, .venv_sample_runner, .venv_dev_tools..."
    rm -rf .venv_test_runner/
    rm -rf .venv_sample_runner/
    rm -rf .venv_dev_tools/
    
    # Remove build artifacts
    echo "INFO: Removing build/ dist/ *.egg-info/ directories..."
    rm -rf build/
    rm -rf dist/
    rm -rf *.egg-info/ # Matches goodmem_client.egg-info

    # Remove pycache files
    echo "INFO: Removing __pycache__ directories and .pyc files..."
    find . -type d -name "__pycache__" -exec rm -r {} +
    find . -type f -name "*.pyc" -delete

    # Remove coverage and test caches
    echo "INFO: Removing .coverage, .pytest_cache, .mypy_cache..."
    rm -f .coverage
    rm -rf .pytest_cache/
    rm -rf .mypy_cache/
    
    # Add other specific files/directories to clean if needed
    # e.g., rm -rf docs/ # If you want to clean generated docs (be careful)

    echo "INFO: Cleanup complete."
else
    echo "INFO: Cleanup cancelled."
fi
