#!/usr/bin/env bash

set -euo pipefail

repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
events="$repo_dir/config/dot/quickshell/services/StatusEvents.qml"
focus="$repo_dir/config/dot/quickshell/services/FocusSession.qml"
devices="$repo_dir/config/dot/quickshell/services/DeviceEvents.qml"
privacy="$repo_dir/config/dot/quickshell/services/PrivacyState.qml"

fail() {
    printf 'curated-events policy: %s\n' "$1" >&2
    exit 1
}

rg -q 'action === "open-workspace"' "$events" || fail 'broker cannot route a retained workspace action'
rg -q 'actionId: "open-workspace"' "$focus" || fail 'focus completion does not retain an actionable workspace destination'
rg -q 'actionData: String\(finishedWorkspaceId\)' "$focus" || fail 'focus completion omits its workspace id'
rg -q 'id: discoverySettle' "$devices" || fail 'device discovery has no silent initialization window'
! rg -Uq 'Component\.onCompleted:[^{\n]*\{[^}]*outputInitialized = true' "$devices" || fail 'output monitoring announces initial discovery'
rg -Uq 'function clearFixture\(\): void \{[^}]*initialized = false' "$privacy" || fail 'leaving a fixture can emit a false privacy transition'

printf 'curated-events policy: PASS\n'
