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

root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)

test -f "${root}/package.xml"
test -f "${root}/CMakeLists.txt"
test ! -e "${root}/src/mtran_ros2/package.xml"
grep -q '<name>mtran</name>' "${root}/package.xml"
grep -q 'project(mtran)' "${root}/CMakeLists.txt"
if grep -q 'build_mtranserver.sh' "${root}/CMakeLists.txt"; then
  echo "CMakeLists.txt still installs the removed build_mtranserver.sh" >&2
  exit 1
fi
grep -q 'mtran/srv/TranslateEnglishToChinese' "${root}/README.md"
if rg -n 'mtran_ros2' "${root}" \
    -g '!docs/superpowers/**' \
    -g '!vendor/**' \
    -g '!test/**' \
    -g '!build/**' \
    -g '!install/**' \
    -g '!log/**'; then
  echo "implementation files still reference mtran_ros2" >&2
  exit 1
fi
