#!/usr/bin/env bash
set -euo pipefail

readonly expected="43b62ac440646c2a5071ede5c671888c0c957236"
readonly actual="$(git -C third_party/n3n rev-parse HEAD)"
readonly patch="patches/n3n/embedded-mobile-integration.patch"

if [[ "$actual" != "$expected" ]]; then
	echo >&2 "Unexpected n3n revision: $actual (expected $expected)"
	exit 1
fi

if [[ -n "$(git -C third_party/n3n status --short --untracked-files=no)" ]]; then
	if ! git -C third_party/n3n apply --check --reverse "../../$patch"; then
		echo >&2 "The pinned n3n source contains unapproved tracked modifications."
		exit 1
	fi
	echo "approved n3n embedded patch verified: $patch"
fi

echo "n3n revision verified: $actual"
