#!/usr/bin/env bash
set -u

has_schema() {
  gsettings list-schemas 2>/dev/null | grep -Fxq "$1"
}

has_key() {
  local schema="$1" key="$2"
  has_schema "$schema" && gsettings list-keys "$schema" 2>/dev/null | grep -Fxq "$key"
}

reset_key() {
  local schema="$1" key="$2"
  if has_key "$schema" "$key"; then
    gsettings reset "$schema" "$key" >/dev/null 2>&1 || true
  fi
}

if command -v gnome-extensions >/dev/null 2>&1; then
  gnome-extensions disable brz-healthos-shell@brztermin.com >/dev/null 2>&1 || true
fi

reset_key org.gnome.desktop.interface icon-theme
reset_key org.gnome.desktop.interface gtk-theme
reset_key org.gnome.desktop.interface cursor-theme
reset_key org.gnome.desktop.interface color-scheme
reset_key org.gnome.desktop.wm.preferences button-layout

# Restore dock keys to distribution defaults rather than guessing Ubuntu values.
for key in dock-position extend-height always-center-icons dock-fixed autohide intellihide \
  intellihide-mode autohide-in-fullscreen require-pressure-to-show show-delay hide-delay \
  animation-time dash-max-icon-size \
  custom-theme-shrink transparency-mode background-opacity custom-background-color \
  background-color running-indicator-style click-action show-trash show-mounts \
  show-show-apps-button show-apps-at-top show-apps-always-in-the-edge apply-custom-theme; do
  reset_key org.gnome.shell.extensions.dash-to-dock "$key"
done

printf '%s\n' 'BRZ Shell customization disabled for this user. Log out and back in.'
