#!/usr/bin/env bash
# Project Scope Review - Check for scope creep

set -e

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

echo "=== 🔍 Project Scope Review ==="
echo ""

# Check for enterprise architecture contracts
echo "Checking for Enterprise Architecture contracts..."
DIAMOND_EXISTS=$(find contracts -name "*Diamond*" -o -name "*diamond*" 2>/dev/null | wc -l)
ERC_FACETS=$(find contracts -name "*ERC*Facet*" -o -name "*Facet*" 2>/dev/null | wc -l)
ISO_REGISTRY=$(find contracts -name "*ISO*" -o -name "*Registry*" 2>/dev/null | wc -l)
FIREFLY_CONTRACTS=$(find contracts -name "*FireFly*" -o -name "*Firefly*" 2>/dev/null | wc -l)

echo "  Diamond contracts: $DIAMOND_EXISTS"
echo "  ERC Facet contracts: $ERC_FACETS"
echo "  ISO Registry contracts: $ISO_REGISTRY"
echo "  FireFly contracts: $FIREFLY_CONTRACTS"

# Check documentation vs implementation
echo ""
echo "Checking documentation vs implementation..."
ENTERPRISE_DOCS=$(find docs -name "*ENTERPRISE*" -o -name "*DIAMOND*" -o -name "*FIREFLY*" 2>/dev/null | wc -l)
echo "  Enterprise documentation files: $ENTERPRISE_DOCS"

# Check for orphaned files
echo ""
echo "Checking for orphaned/unused files..."
ORPHANED_SCRIPTS=$(find scripts -name "*.sh" ! -executable 2>/dev/null | wc -l)
echo "  Non-executable scripts: $ORPHANED_SCRIPTS"

# Check for duplicate functionality
echo ""
echo "Checking for duplicate contracts..."
DUPLICATE_WETH=$(find contracts -name "*WETH*" 2>/dev/null | wc -l)
DUPLICATE_CCIP=$(find contracts -name "*CCIP*" 2>/dev/null | wc -l)
echo "  WETH contracts: $DUPLICATE_WETH"
echo "  CCIP contracts: $DUPLICATE_CCIP"

# Summary
echo ""
echo "=== 📊 Scope Review Summary ==="
if [ "$DIAMOND_EXISTS" -eq 0 ] && [ "$ENTERPRISE_DOCS" -gt 0 ]; then
    echo "⚠️  WARNING: Enterprise architecture documented but not implemented"
fi

if [ "$ORPHANED_SCRIPTS" -gt 0 ]; then
    echo "⚠️  WARNING: Found non-executable scripts"
fi

echo "✅ Scope review complete"
