#!/usr/bin/env bash
# Quick Verification - Run All Checks
# Convenience script to run all verification checks before deployment

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Try to find project root - could be at same level or in smom-dbis-138-proxmox subdirectory
if [[ -d "$SCRIPT_DIR/../../smom-dbis-138-proxmox" ]]; then
    PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../smom-dbis-138-proxmox" && pwd)"
elif [[ -d "$SCRIPT_DIR/../.." ]]; then
    PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
else
    PROJECT_ROOT="$SCRIPT_DIR/../.."
fi

SOURCE_PROJECT="${1:-/home/intlc/projects/smom-dbis-138}"

echo "════════════════════════════════════════════════════════"
echo "  Complete Verification - All Checks"
echo "════════════════════════════════════════════════════════"
echo ""
echo "Source Project: $SOURCE_PROJECT"
echo ""

# 1. Prerequisites Check
echo "=== 1. Prerequisites Check ==="
if [[ -f "$SCRIPT_DIR/check-prerequisites.sh" ]]; then
    "$SCRIPT_DIR/check-prerequisites.sh" "$SOURCE_PROJECT" || {
        echo ""
        echo "❌ Prerequisites check failed. Fix issues before continuing."
        exit 1
    }
elif [[ -f "$PROJECT_ROOT/scripts/validation/check-prerequisites.sh" ]]; then
    "$PROJECT_ROOT/scripts/validation/check-prerequisites.sh" "$SOURCE_PROJECT" || {
        echo ""
        echo "❌ Prerequisites check failed. Fix issues before continuing."
        exit 1
    }
else
    echo "⚠ check-prerequisites.sh not found, skipping..."
fi

echo ""
echo "=== 2. Storage Configuration (requires root on Proxmox host) ==="
if [[ $EUID -eq 0 ]] && command -v pvesm &>/dev/null; then
    if [[ -f "$SCRIPT_DIR/verify-storage-config.sh" ]]; then
        "$SCRIPT_DIR/verify-storage-config.sh" || {
            echo ""
            echo "⚠ Storage verification had issues. Review output above."
        }
    elif [[ -f "$PROJECT_ROOT/scripts/validation/verify-storage-config.sh" ]]; then
        "$PROJECT_ROOT/scripts/validation/verify-storage-config.sh" || {
            echo ""
            echo "⚠ Storage verification had issues. Review output above."
        }
    else
        echo "⚠ verify-storage-config.sh not found, skipping..."
    fi
else
    echo "  Skipping (not running as root on Proxmox host)"
    echo "  To verify storage, run: sudo ./scripts/validation/verify-storage-config.sh"
fi

echo ""
echo "=== 3. Network Configuration ==="
if [[ -f "$SCRIPT_DIR/verify-network-config.sh" ]]; then
    "$SCRIPT_DIR/verify-network-config.sh" || {
        echo ""
        echo "⚠ Network verification had issues. Review output above."
    }
elif [[ -f "$PROJECT_ROOT/scripts/validation/verify-network-config.sh" ]]; then
    "$PROJECT_ROOT/scripts/validation/verify-network-config.sh" || {
        echo ""
        echo "⚠ Network verification had issues. Review output above."
    }
else
    echo "⚠ verify-network-config.sh not found, skipping..."
fi

echo ""
echo "════════════════════════════════════════════════════════"
echo "  Verification Complete"
echo "════════════════════════════════════════════════════════"
echo ""
echo "If all checks passed, you're ready to deploy:"
echo "  sudo ./scripts/deployment/deploy-phased.sh --source-project $SOURCE_PROJECT"
echo ""

