#!/usr/bin/env bash
# Complete Chain-138 verification - runs all checks

set -e

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

# Color codes

echo "==================================================================="
echo "  CHAIN-138 COMPLETE VERIFICATION"
echo "==================================================================="

# Run all verification scripts
log_info "Running full deployment verification..."
./scripts/deployment/verify-chain138-full-deployment.sh
FULL_DEPLOY_STATUS=$?

log_info "Running services verification..."
./scripts/deployment/verify-chain138-services.sh
SERVICES_STATUS=$?

log_info "Running cross-check verification..."
./scripts/deployment/cross-check-chain138.sh
CROSS_CHECK_STATUS=$?

echo "==================================================================="
log_info "FINAL SUMMARY"
echo "==================================================================="

TOTAL_ISSUES=0

if [ $FULL_DEPLOY_STATUS -ne 0 ]; then
    log_error "❌ Full Deployment Verification: FAILED"
    TOTAL_ISSUES=$((TOTAL_ISSUES + 1))
else
    log_success "✅ Full Deployment Verification: PASSED"
fi

if [ $SERVICES_STATUS -ne 0 ]; then
    log_error "❌ Services Verification: FAILED"
    TOTAL_ISSUES=$((TOTAL_ISSUES + 1))
else
    log_success "✅ Services Verification: PASSED"
fi

if [ $CROSS_CHECK_STATUS -ne 0 ]; then
    log_error "❌ Cross-Check Verification: FAILED"
    TOTAL_ISSUES=$((TOTAL_ISSUES + 1))
else
    log_success "✅ Cross-Check Verification: PASSED"
fi


if [ $TOTAL_ISSUES -eq 0 ]; then
    log_success "✅✅✅ CHAIN-138 IS FULLY DEPLOYED AND VERIFIED! ✅✅✅"
    exit 0
else
    log_error "❌ Chain-138 verification found $TOTAL_ISSUES issue(s)"
    echo "  Review the reports above for details"
    exit 1
fi
