# Stage the prebuilt Rust AT-SPI semantic agent + its systemd USER unit, with a static
# global-enable symlink so it starts in every graphical session (no `systemctl --global
# enable` needed inside the mmdebstrap chroot).
#
# dist/bin is the ONLY source. There used to be an arm64-only fallback to a committed
# guest/nucleic-a11y-agent/build/ binary, which papered over the fact that CI built this
# crate natively on arm64 and never for amd64 — so the amd64 deb silently skipped staging
# and never reached the repo. naros.yml now cross-builds both arches (musl via zigbuild).
stage() {
  local dest="$1" arch="$2"
  local bin="$OS_DIR/dist/bin/nucleic-a11y-agent-$arch"
  local unit="$OS_DIR/../guest/nucleic-a11y-agent/systemd/nucleic-a11y-agent.service"
  if [ ! -x "$bin" ]; then
    echo "prebuilt binary missing: dist/bin/nucleic-a11y-agent-$arch" > "$dest/.skip-reason"
    return 1
  fi
  install -D -m 0755 "$bin" "$dest/usr/local/bin/nucleic-a11y-agent"
  install -D -m 0644 "$unit" "$dest/usr/lib/systemd/user/nucleic-a11y-agent.service"
  install -d "$dest/etc/systemd/user/graphical-session.target.wants"
  ln -sf /usr/lib/systemd/user/nucleic-a11y-agent.service \
    "$dest/etc/systemd/user/graphical-session.target.wants/nucleic-a11y-agent.service"
}
