#!/bin/bash

# Fix all undefined HVAC_CE_* constants in PHP files
echo "Fixing all undefined HVAC_CE_* constants..."

# Find all PHP files and fix constants
find . -name "*.php" -type f ! -path "./vendor/*" ! -path "./.git/*" ! -path "./node_modules/*" | while read file; do
    if grep -q "HVAC_CE_" "$file"; then
        echo "Fixing $file..."
        # Replace HVAC_CE_PLUGIN_DIR with HVAC_PLUGIN_DIR
        sed -i.bak 's/HVAC_CE_PLUGIN_DIR/HVAC_PLUGIN_DIR/g' "$file"
        # Replace HVAC_CE_PLUGIN_URL with HVAC_PLUGIN_URL  
        sed -i.bak 's/HVAC_CE_PLUGIN_URL/HVAC_PLUGIN_URL/g' "$file"
        # Replace HVAC_CE_VERSION with HVAC_PLUGIN_VERSION
        sed -i.bak 's/HVAC_CE_VERSION/HVAC_PLUGIN_VERSION/g' "$file"
        # Remove backup file
        rm -f "$file.bak"
    fi
done

echo "Done! All HVAC_CE_* constants have been replaced with HVAC_PLUGIN_* equivalents"