# Pull base images then start the full Meezi stack in Docker.
$ErrorActionPreference = "Stop"
$Root = Split-Path -Parent $PSScriptRoot
Push-Location $Root

$images = @(
    "mcr.microsoft.com/dotnet/sdk:10.0",
    "mcr.microsoft.com/dotnet/aspnet:10.0",
    "postgres:16-alpine",
    "redis:7-alpine",
    "node:20-alpine"
)

Write-Host "Pulling base images (use VPN if pulls time out)..." -ForegroundColor Cyan
foreach ($img in $images) {
    Write-Host "  pull $img"
    docker pull $img
    if ($LASTEXITCODE -ne 0) {
        Write-Host "Failed to pull $img. Enable VPN or configure a registry mirror (see docs/DOCKER.md)." -ForegroundColor Red
        Pop-Location
        exit 1
    }
}

Write-Host ""
Write-Host "Building and starting all services..." -ForegroundColor Cyan
docker compose up -d --build
$code = $LASTEXITCODE
Pop-Location
if ($code -ne 0) { exit $code }

Write-Host ""
Write-Host "Meezi is starting:" -ForegroundColor Green
Write-Host "  Dashboard  http://localhost:3101/fa/login"
Write-Host "  API        http://localhost:5080/swagger"
Write-Host "  Health     http://localhost:5080/health"
Write-Host ""
Write-Host "  docker compose ps"
Write-Host "  docker compose logs -f api"
