#!/bin/bash
# run_multiplatform_tests.sh - Run tests across multiple platforms

set -e

echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🌍 Multi-Platform Test Runner"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""

# Detect platform
OS=$(uname -s)
ARCH=$(uname -m)

echo "Platform: $OS / $ARCH"
echo ""

# Run platform detection tests
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📋 Platform Detection Tests"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
nim c -r tests/test_multiplatform.nim
echo ""

# Run container tests if available
if command -v docker &> /dev/null || command -v podman &> /dev/null; then
    echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
    echo "🐳 Container Tests"
    echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
    nim c -r tests/test_container_builds.nim
    echo ""
fi

# Platform-specific tests
case "$OS" in
    Linux)
        echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
        echo "🐧 Linux-Specific Tests"
        echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"

        # Check for systemd
        if command -v systemctl &> /dev/null; then
            echo "✅ systemd available"
        fi

        # Check for package managers
        if command -v apt &> /dev/null; then
            echo "✅ apt available (Debian/Ubuntu)"
        fi
        if command -v dnf &> /dev/null; then
            echo "✅ dnf available (Fedora/RHEL)"
        fi
        if command -v pacman &> /dev/null; then
            echo "✅ pacman available (Arch)"
        fi
        if command -v zypper &> /dev/null; then
            echo "✅ zypper available (openSUSE)"
        fi

        echo ""
        ;;

    Darwin)
        echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
        echo "🍎 macOS-Specific Tests"
        echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"

        # Check for Homebrew
        if command -v brew &> /dev/null; then
            echo "✅ Homebrew available"
        fi

        # Check for MacPorts
        if command -v port &> /dev/null; then
            echo "✅ MacPorts available"
        fi

        echo ""
        ;;

    FreeBSD|OpenBSD|NetBSD|DragonFly)
        echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
        echo "👹 BSD-Specific Tests"
        echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"

        # Check for pkg
        if command -v pkg &> /dev/null; then
            echo "✅ pkg available"
        fi

        echo ""
        ;;
esac

# Architecture-specific tests
case "$ARCH" in
    x86_64|amd64)
        echo "✅ x86_64 architecture detected"
        ;;
    aarch64|arm64)
        echo "✅ ARM64 architecture detected"
        ;;
    armv7*)
        echo "✅ ARMv7 architecture detected"
        ;;
esac

echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✅ Multi-Platform Tests Complete"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
