param(
    [string]$EmmaHome = 'C:\Emma\current'
)

$ErrorActionPreference = 'Stop'

$agentExe = Join-Path $EmmaHome 'runtime\emma-agent.exe'

if (-not (Test-Path $agentExe)) {
    throw "emma-agent.exe nicht gefunden: $agentExe"
}

$env:EMMA_HOME = $EmmaHome
$env:EMMA_UI_DIR = Join-Path $EmmaHome 'ui'
$env:PORT = '3000'

$logDir = Join-Path $EmmaHome 'logs'
New-Item -ItemType Directory -Force -Path $logDir | Out-Null
Set-Location $EmmaHome

$logFile = Join-Path $logDir 'service.log'
& $agentExe run *>> $logFile
