import os

RENAME_MAP = [
    ('polkadot', 'pezkuwi'),
    ('substrate', 'bizinikiwi'),
    ('cumulus', 'pezcumulus'),
    ('parachain', 'teyrchain'),
    ('rococo', 'pezkuwichain'),
    ('westend', 'zagros'),
    ('frame', 'pezframe'),
    ('pallet', 'pezpallet'),
    ('sp-', 'pezsp-'),
    ('sc-', 'pezsc-'),
]

def main():
    # Use depth-first to handle directories correctly
    for root, dirs, files in os.walk('.', topdown=False):
        if '.git' in root or 'target' in root:
            continue
            
        # Rename files
        for name in files:
            new_name = name
            for old, new in RENAME_MAP:
                if old in new_name and not new in new_name:
                    new_name = new_name.replace(old, new)
            
            if new_name != name:
                old_path = os.path.join(root, name)
                new_path = os.path.join(root, new_name)
                os.rename(old_path, new_path)
                # print(f"Renamed file: {old_path} -> {new_path}")

        # Rename directories
        for name in dirs:
            if name == '.git' or name == 'target':
                continue
            new_name = name
            for old, new in RENAME_MAP:
                if old in new_name and not new in new_name:
                    new_name = new_name.replace(old, new)
            
            if new_name != name:
                old_path = os.path.join(root, name)
                new_path = os.path.join(root, new_name)
                os.rename(old_path, new_path)
                # print(f"Renamed dir: {old_path} -> {new_path}")

if __name__ == "__main__":
    main()
