#!/bin/bash
# 删除 YG_FT_Base 虚拟环境脚本
# 使用方法: bash delete_venv.sh

# 自动修复脚本换行符
if grep -q $'\r' "$0"; then
    echo "检测到 Windows 换行符，自动修复中..."
    sed -i 's/\r$//' "$0"
    echo "修复完成，重新执行脚本..."
    exec "$0"
fi

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VENV_NAME="B_venv"
VENV_PATH="$SCRIPT_DIR/$VENV_NAME"

echo "===================================="
echo "YG_FT_Base 虚拟环境删除脚本"
echo "===================================="
echo ""

# 检查虚拟环境是否存在
if [ ! -d "$VENV_PATH" ]; then
    echo "虚拟环境 '$VENV_NAME' 不存在，无需删除。"
    exit 0
fi

# 确认删除
read -p "确定要删除虚拟环境 '$VENV_NAME' 吗？这将删除所有已安装的包。(y/n): " choice

if [[ "$choice" != "y" && "$choice" != "Y" ]]; then
    echo "已取消操作。"
    exit 0
fi

# 删除虚拟环境
echo ""
echo "🗑️  删除虚拟环境..."
rm -rf "$VENV_PATH"

if [ $? -eq 0 ]; then
    echo "✅ 虚拟环境 '$VENV_NAME' 已删除！"
else
    echo "❌ 删除失败，请检查权限。"
    exit 1
fi

echo ""
echo "===================================="
echo "删除完成！"
echo "===================================="
echo ""
echo "如需重新创建虚拟环境，请运行:"
echo "  bash create_venv.sh"
echo ""
