#!/usr/bin/env bash

# Run All Validations
# This script runs all validation tests

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../lib/init.sh"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"


log_success "Running All Validations..."

# Run all validation scripts
VALIDATION_SCRIPTS=(
    "validate-genesis.sh"
    "validate-deployment.sh"
    "validate-network-policies.sh"
    "validate-rbac.sh"
    "validate-hpa.sh"
    "validate-monitoring.sh"
    "security-scan.sh"
    "load-test.sh"
    "disaster-recovery-test.sh"
)

FAILED=0
PASSED=0

for script in "${VALIDATION_SCRIPTS[@]}"; do
    SCRIPT_PATH="$SCRIPT_DIR/$script"
    
    if [ -f "$SCRIPT_PATH" ]; then
        log_warn "Running $script..."
        echo "----------------------------------------"
        
        if bash "$SCRIPT_PATH"; then
            log_success "✓ $script passed"
            PASSED=$((PASSED + 1))
        else
            log_error "✗ $script failed"
            FAILED=$((FAILED + 1))
        fi
        
    else
        log_warn "⚠ $script not found"
    fi
done

# Summary
log_success "Validation Summary:"
echo -e "  Passed: $PASSED"
echo -e "  Failed: $FAILED"
echo -e "  Total: $((PASSED + FAILED))"

if [ $FAILED -eq 0 ]; then
    log_success "✓ All validations passed"
    exit 0
else
    log_error "✗ Some validations failed"
    exit 1
fi

