#!/bin/bash

replaceRandomUsernames() 
{
    local file="$1"

    # Only scan for placeholders that actually exist in the file
    local existing_placeholders=$(runInstallOp grep -oE 'RANDOMIZEDUSERNAME[0-9]+' "$file" 2>/dev/null | sort -u)
    
    if [[ -n "$existing_placeholders" ]]; then
        while IFS= read -r username_placeholder; do
            if [[ -n "$username_placeholder" ]]; then
                local random_username=$(generateRandomUsername)
                runInstallOp sed -i 's/'"${username_placeholder}"'/'"${random_username}"'/g' "$file"
                checkSuccess "Updated ${username_placeholder} in $(basename "$file")."
            fi
        done <<< "$existing_placeholders"
    fi
}
