#!/bin/bash

echo "=========================================="
echo "Testing connectivity to required sites..."
echo "=========================================="
echo ""

# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

test_site() {
    local site=$1
    echo -n "Testing $site ... "
    
    if curl -s --connect-timeout 5 -I "https://$site" > /dev/null 2>&1; then
        echo -e "${GREEN}✓ OK${NC}"
        return 0
    else
        echo -e "${RED}✗ FAILED${NC}"
        return 1
    fi
}

# Test NPM
echo "=== NPM Registry ==="
test_site "registry.npmjs.org"
echo ""

# Test Prisma
echo "=== Prisma Binaries ==="
test_site "binaries.prisma.sh"
test_site "binaries.prismacdn.com"
echo ""

# Test Docker
echo "=== Docker Registry ==="
test_site "registry.hub.docker.com"
test_site "registry-1.docker.io"
echo ""

# Test DNS
echo "=== DNS Resolution ==="
echo -n "Checking DNS for registry.npmjs.org ... "
if nslookup registry.npmjs.org > /dev/null 2>&1; then
    echo -e "${GREEN}✓ OK${NC}"
else
    echo -e "${RED}✗ FAILED${NC}"
fi

echo ""
echo "=========================================="
echo "Summary:"
echo "=========================================="
echo ""
echo "If any tests failed, you need to:"
echo "1. Use Shecan/Electro DNS"
echo "2. Use VPN/Proxy"
echo "3. Build on external server"
echo ""
echo "See REQUIRED_SITES.md for details"
