#!/bin/bash

# Sync helper files to all modules
# Run this when core interfaces change

CORE_HELPERS="core/include/warfactory"
MODULE_DIRS="modules/*/shared"

echo "🔄 Syncing helper files to all modules..."

if [ ! -d "$CORE_HELPERS" ]; then
    echo "❌ Core helpers directory not found: $CORE_HELPERS"
    exit 1
fi

for module_dir in $MODULE_DIRS; do
    if [ -d "$module_dir" ]; then
        module_name=$(dirname "$module_dir" | basename)
        echo "   → Syncing to $module_name"

        # Copy core interfaces
        cp "$CORE_HELPERS/IModule.h" "$module_dir/"
        cp "$CORE_HELPERS/ISocket.h" "$module_dir/"

        # Copy base helper (if exists)
        if [ -f "modules/factory/shared/ModuleBase.h" ]; then
            cp "modules/factory/shared/ModuleBase.h" "$module_dir/"
        fi
    fi
done

echo "✅ Helper sync completed!"
echo ""
echo "📋 Next steps:"
echo "   cd modules/factory && cmake . && make factory-module"
echo "   cd modules/economy && cmake . && make economy-module"
echo "   cd modules/logistic && cmake . && make logistic-module"