#!/usr/bin/env bash
# Fix identified script syntax errors

set -e

cd "$(dirname "$0")/../.."

echo "=== Fixing Script Syntax Errors ==="

# Fix 1: check-mainnet-deployment-status.sh line 61
echo "Fixing check-mainnet-deployment-status.sh..."
if grep -q 'echo " (depends on: $deps)"' scripts/deployment/check-mainnet-deployment-status.sh; then
    # The issue is with the parentheses in the echo - need to escape or quote properly
    sed -i '61s/.*/            echo " (depends on: '"'"'$deps'"'"')"/' scripts/deployment/check-mainnet-deployment-status.sh
    echo "✅ Fixed check-mainnet-deployment-status.sh"
fi

# Fix 2: deploy-all.sh line 282
echo "Checking deploy-all.sh..."
if bash -n scripts/deployment/deploy-all.sh 2>&1 | grep -q "line 282"; then
    # Read around line 282 to understand the issue
    sed -n '278,285p' scripts/deployment/deploy-all.sh
    echo "⚠️  Manual review needed for deploy-all.sh:282"
fi

# Fix 3: validate-deployment-config.sh line 339
echo "Checking validate-deployment-config.sh..."
if bash -n scripts/deployment/validate-deployment-config.sh 2>&1 | grep -q "line 339"; then
    # Read around line 339 to understand the issue
    sed -n '335,342p' scripts/deployment/validate-deployment-config.sh
    echo "⚠️  Manual review needed for validate-deployment-config.sh:339"
fi

# Validate all fixes
echo ""
echo "Validating all scripts..."
./scripts/automation/validate-all-scripts.sh

echo "✅ Script error fixes complete"
