#!/usr/bin/env bash

set -euo pipefail

repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
body="$repo_dir/config/dot/quickshell/modules/overview/OverviewBody.qml"
thumbnail="$repo_dir/config/dot/quickshell/modules/overview/WindowThumbnail.qml"
workspace="$repo_dir/config/dot/quickshell/modules/overview/WorkspaceCard.qml"

fail() {
    printf 'overview-window-actions contract: %s\n' "$1" >&2
    exit 1
}

rg -q 'function addressOf\(toplevel: var\): string' "$body" || fail 'address normalization boundary is missing'
rg -q 'function closeToplevel\(toplevel: var\): void' "$body" || fail 'address-scoped close boundary is missing'
rg -q 'function moveToplevel\(toplevel: var, workspaceName: string\): void' "$body" || fail 'address-scoped move boundary is missing'
rg -q 'function restoreToplevel\(toplevel: var\): void' "$body" || fail 'scratchpad restore boundary is missing'
rg -q 'hl\.dsp\.window\.close\(\{ window = ' "$body" || fail 'close does not use the modern exact-window dispatcher'
rg -q 'hl\.dsp\.window\.move\(\{ workspace = ' "$body" || fail 'move does not use the modern exact-window dispatcher'
rg -q 'signal closeRequested' "$thumbnail" || fail 'thumbnail has no close intent'
rg -q 'Drag\.active:' "$thumbnail" || fail 'thumbnail has no drag source'
rg -q 'DropArea \{' "$workspace" || fail 'workspace card has no drop target'
qs ipc show | rg -q '^target overview-actions$' || fail 'live action contract surface is missing'

printf 'overview-window-actions contract: PASS\n'
