#!/usr/bin/env bash

# Public Settings.qml values are the compatibility surface consumed throughout
# the shell. Once a value becomes user-configurable, this file must read it from
# DesktopPreferences rather than keeping a second hardcoded source of truth.

set -euo pipefail

repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
settings="$repo_dir/config/dot/quickshell/config/Settings.qml"

fail() {
    printf 'settings hardcoded values contract: %s\n' "$1" >&2
    exit 1
}

properties=(
    temperatureUnit
    weatherRefreshMinutes
    vitalsIntervalMs
    notificationTimeoutMs
    notificationTimeoutCriticalMs
    notificationHistoryLimit
    maxVisibleToasts
    screenshotDir
    recordingDir
    recorderArgs
)

for property in "${properties[@]}"; do
    count="$(rg -c \
        "^[[:space:]]*readonly property [A-Za-z]+ ${property}: DesktopPreferences\\.get\\(\"${property}\"\\)[[:space:]]*(//.*)?$" \
        "$settings" || true)"
    [[ "$count" == "1" ]] \
        || fail "$property must use DesktopPreferences.get(\"$property\") exactly once"
done

# dockPinned was already migrated on the shared branch. Pinning it here keeps a
# later bulk edit from accidentally restoring the old hardcoded app list.
rg -q '^[[:space:]]*readonly property var dockPinned: DesktopPreferences\.get\("dockPinned"\)[[:space:]]*$' "$settings" \
    || fail 'dockPinned no longer reads DesktopPreferences exactly'

printf 'settings hardcoded values contract: PASS\n'
