#!/bin/bash

set -euo pipefail

echo "==> Backing up your project with git"
git add . && git commit -am "Pre-rename backup" || true

echo "==> 1. Updating root Cargo.toml"
sed -i 's/^name = "mumu"/name = "mumu"/' Cargo.toml

echo "==> 2. Updating plugin dependencies in all Cargo.toml files"
find . -type f -name Cargo.toml -exec sed -i 's/mumu = { path = "\.\." }/mumu = { path = ".." }/g' {} +

echo "==> 3. Changing use/import statements in all Rust source files"
find . -type f -name '*.rs' -exec sed -i 's/\<mumu::/mumu::/g' {} +

echo "==> 4. Updating lib references in Cargo.toml (optional, for aesthetics)"
find . -type f -name Cargo.toml -exec sed -i 's/name = "mumu/name = "mumu/g' {} +

echo "==> 5. Makefile and scripts"
sed -i 's/mumu\b/mumu/g' Makefile || true

echo "==> 6. README and docs"
find . -type f \( -name '*.md' -o -name '*.mu' -o -name '*.json' \) -exec sed -i 's/\bmumu\b/mumu/g' {} +

echo "==> All occurrences of 'mumu' renamed to 'mumu' (where appropriate)."
echo "==> Now run: cargo clean && cargo build --workspace"
echo "==> If you have CI, update any external references to 'mumu' as needed."
echo "==> Done. Review changes with 'git diff'. If happy: git commit -am 'rename mumu -> mumu'"

