#!/bin/bash
REPORT="$PROJECT_ROOT/logs/comprehensive-review-$(date +%Y%m%d-%H%M%S).md"
mkdir -p logs

cat > "$REPORT" << 'REPORTEOF'
# Comprehensive Project Review Report

Generated: $(date '+%Y-%m-%d %H:%M:%S')

## Summary

This report identifies inconsistencies, gaps, and dependency issues across the project.

---

## 1. VMID Consistency

### Expected VMID Ranges
- **Validators**: 1000-1004 (5 nodes)
- **Sentries**: 1500-1503 (4 nodes)  
- **RPC**: 2500-2502 (3 nodes)

### Files with Old VMID References (106-117)

REPORTEOF

grep -rE "\b(106|107|108|109|110|111|112|113|114|115|116|117)\b" \
  smom-dbis-138-proxmox/ docs/ 2>/dev/null | \
  grep -v node_modules | grep -v ".git" | \
  grep -v "EXPECTED_CONTAINERS.md" | \
  grep -v "VMID_ALLOCATION.md" | \
  grep -v "HISTORICAL" | \
  cut -d: -f1 | sort -u | sed 's|^|- `|;s|$|`|' >> "$REPORT"

cat >> "$REPORT" << 'REPORTEOF'

---

## 2. IP Address Consistency

### Expected IP Range
- Base subnet: 192.168.11.0/24
- Validators: 192.168.11.100-104
- Sentries: 192.168.11.150-153
- RPC: 192.168.11.250-252

### Files with Old IP References (10.3.1.X)

REPORTEOF

grep -rE "10\.3\.1\." smom-dbis-138-proxmox/ docs/ 2>/dev/null | \
  grep -v node_modules | grep -v ".git" | \
  cut -d: -f1 | sort -u | sed 's|^|- `|;s|$|`|' >> "$REPORT"

cat >> "$REPORT" << 'REPORTEOF'

---

## 3. Dependencies

### Required Tools Status

REPORTEOF

for tool in pct jq sshpass timeout openssl curl wget; do
  if command -v "$tool" >/dev/null 2>&1; then
    echo "- ✅ $tool" >> "$REPORT"
  else
    echo "- ❌ $tool - MISSING" >> "$REPORT"
  fi
done

cat >> "$REPORT" << 'REPORTEOF'

### Configuration Files Status

REPORTEOF

for file in "smom-dbis-138-proxmox/config/proxmox.conf" "smom-dbis-138-proxmox/config/network.conf"; do
  if [[ -f "$file" ]]; then
    echo "- ✅ \`$file\`" >> "$REPORT"
  else
    echo "- ❌ Missing: \`$file\`" >> "$REPORT"
  fi
done

cat >> "$REPORT" << 'REPORTEOF'

---

## 4. Documentation Issues

### Documents with Outdated References

- \`docs/EXPECTED_CONTAINERS.md\` - Contains old VMID ranges (106-117)
- \`docs/VMID_ALLOCATION.md\` - Contains historical VMID ranges (1100-1122)

These are historical/migration documents and may be kept for reference but should be clearly marked.

---

## Recommendations

1. Update active documentation files to use current VMID ranges
2. Update IP address references from 10.3.1.X to 192.168.11.X
3. Mark historical documentation files clearly
4. Ensure all required tools are documented and available
5. Verify configuration consistency across all scripts

REPORTEOF

echo "Report generated: $REPORT"
cat "$REPORT"
