#!/bin/bash

#######################################
# SKG UCP - Uninstall Script
#######################################

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

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

echo -e "${RED}"
echo "=============================================="
echo "       SKG UCP - Uninstall Script            "
echo "=============================================="
echo -e "${NC}"
echo ""
echo -e "${YELLOW}Warning: This will stop and remove SKG UCP from PM2.${NC}"
echo -e "${YELLOW}Your files and database will NOT be deleted.${NC}"
echo ""
read -p "Are you sure you want to continue? (y/n): " CONFIRM

if [[ ! "$CONFIRM" =~ ^[Yy]$ ]]; then
    echo "Uninstall cancelled."
    exit 0
fi

echo ""
echo -e "${YELLOW}Stopping SKG UCP...${NC}"
pm2 stop skg-ucp 2>/dev/null || true
pm2 delete skg-ucp 2>/dev/null || true
pm2 save 2>/dev/null || true

echo -e "${GREEN}SKG UCP has been stopped and removed from PM2.${NC}"
echo ""
echo "To completely remove SKG UCP, manually delete:"
echo "  - Application folder: ${SCRIPT_DIR}"
echo "  - Database (via MySQL/MariaDB)"
echo "  - Apache/Nginx config (if configured)"
echo ""
echo "To reinstall, run: ./install.sh"
