#!/bin/bash
set -e

case "$1" in
    purge)
        # Remove user and group
        if getent passwd skyview >/dev/null 2>&1; then
            deluser --system skyview >/dev/null 2>&1 || true
        fi
        
        if getent group skyview >/dev/null 2>&1; then
            delgroup --system skyview >/dev/null 2>&1 || true
        fi
        
        # Remove data directories
        rm -rf /var/lib/skyview
        rm -rf /var/log/skyview
        
        # Remove config directory if empty
        rmdir /etc/skyview 2>/dev/null || true
        
        echo "SkyView has been completely removed."
        ;;
    
    remove)
        # Reload systemd after service file removal
        systemctl daemon-reload
        ;;
esac

exit 0