# Test connectivity to required sites for Docker build

Write-Host "==========================================" -ForegroundColor Cyan
Write-Host "Testing connectivity to required sites..." -ForegroundColor Cyan
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host ""

function Test-Site {
    param($site)
    
    Write-Host "Testing $site ... " -NoNewline
    
    try {
        $response = Invoke-WebRequest -Uri "https://$site" -Method Head -TimeoutSec 5 -ErrorAction Stop
        Write-Host "✓ OK" -ForegroundColor Green
        return $true
    } catch {
        Write-Host "✗ FAILED" -ForegroundColor Red
        return $false
    }
}

# Test NPM
Write-Host "=== NPM Registry ===" -ForegroundColor Yellow
Test-Site "registry.npmjs.org"
Write-Host ""

# Test Prisma
Write-Host "=== Prisma Binaries ===" -ForegroundColor Yellow
Test-Site "binaries.prisma.sh"
Test-Site "binaries.prismacdn.com"
Write-Host ""

# Test Docker
Write-Host "=== Docker Registry ===" -ForegroundColor Yellow
Test-Site "registry.hub.docker.com"
Test-Site "registry-1.docker.io"
Write-Host ""

# Test DNS
Write-Host "=== DNS Resolution ===" -ForegroundColor Yellow
Write-Host "Checking DNS for registry.npmjs.org ... " -NoNewline
try {
    $dns = Resolve-DnsName registry.npmjs.org -ErrorAction Stop
    Write-Host "✓ OK" -ForegroundColor Green
} catch {
    Write-Host "✗ FAILED" -ForegroundColor Red
}

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