Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

# Load shared utilities
$utilsPath = Join-Path $PSScriptRoot '..\lib\utils.ps1'
. $utilsPath

.\scripts\Windows\starter.ps1
if ($LASTEXITCODE -ne 0) {
    exit $LASTEXITCODE
}

if (-not (Test-Path '.env'))
{
    Write-Warning-Custom ".env file not found. Exiting without running Docker steps."
    exit 0
}

# Check system requirements
if (-not (Test-SystemRequirements -MinCpu 4 -MinRamGB 6 -MinDiskGB 20))
{
    exit 1
}

# Pull Docker images
Write-Step "Pulling images..."
docker compose pull
if ($LASTEXITCODE -ne 0) {
    Write-Error-Custom "Failed to pull Docker images"
    exit $LASTEXITCODE
}
Write-Success "Images pulled successfully"

# Build Docker images
Write-Step "Building images..."
docker compose build
if ($LASTEXITCODE -ne 0) {
    Write-Error-Custom "Failed to build Docker images"
    exit $LASTEXITCODE
}
Write-Success "Images built successfully"

Write-Result ""
Write-Result "You can now use run.ps1 script or run: lessy.py run"
