#!/bin/bash

# Check if running on macOS
if [[ "$OSTYPE" != "darwin"* ]]; then
    echo "This script only supports macOS systems."
    exit 1
fi

# Check Python version
python_cmd="python3"
if ! command -v python3 &> /dev/null; then
    if command -v python &> /dev/null; then
        python_cmd="python"
    else
        echo "Error: Python interpreter not found."
        echo "Please install Python 3.6 or higher."
        exit 1
    fi
fi

# Check Python version
python_version=$($python_cmd --version 2>&1 | awk '{print $2}')
required_version="3.8.0"

if [ "$(printf '%s\n' "$required_version" "$python_version" | sort -V | head -n1)" != "$required_version" ]; then
    echo "Current Python version $python_version is lower than $required_version."
    echo "Please upgrade your Python version."
    exit 1
fi

echo "Uninstalling Vw3000 service on macOS..."
cd ./Vw3000.en/Vw3000

# Use sudo to run the uninstallation script
sudo $python_cmd uninstall_macos_service.py

cd ./../..

echo "Uninstallation complete!"