#!/bin/bash
set -euo pipefail

WATCHDOG_SCRIPT="/opt/terkom-ng/terkom/scripts/watchdog.sh"
SERVICE_FILE="/etc/systemd/system/terkom-watchdog.service"
TIMER_FILE="/etc/systemd/system/terkom-watchdog.timer"
STATE_DIR="/run/terkom-watchdog"

echo "[INFO] Uninstalling Terkom Watchdog..."

systemctl disable --now terkom-watchdog.timer 2>/dev/null || true
systemctl stop terkom-watchdog.service 2>/dev/null || true

rm -f "$TIMER_FILE"
rm -f "$SERVICE_FILE"
rm -f "$WATCHDOG_SCRIPT"
rm -rf "$STATE_DIR"

systemctl daemon-reload
systemctl reset-failed 2>/dev/null || true

echo "[OK] Uninstall complete"
echo "[INFO] Remaining status:"
systemctl status terkom-watchdog.timer --no-pager 2>&1 || true
systemctl status terkom-watchdog.service --no-pager 2>&1 || true
