param(
    [string]$DockerHost = "ssh://docker-gpu.cin.su",
    [string]$ComposeFile = "core/deploy/docker-gpu/llama-cpp/compose.yaml",
    [string]$EnvFile = "core/deploy/docker-gpu/llama-cpp/.env.example",
    [switch]$ConfigOnly,
    [switch]$Pull,
    [switch]$Down
)

$ErrorActionPreference = "Stop"

if (-not (Test-Path -LiteralPath $ComposeFile)) {
    throw "Compose file not found: $ComposeFile"
}

if (-not (Test-Path -LiteralPath $EnvFile)) {
    throw "Env file not found: $EnvFile"
}

$baseArgs = @(
    "--host", $DockerHost,
    "compose",
    "--env-file", $EnvFile,
    "-f", $ComposeFile
)

if ($ConfigOnly) {
    docker @baseArgs config
    exit $LASTEXITCODE
}

if ($Down) {
    docker @baseArgs down
    exit $LASTEXITCODE
}

if ($Pull) {
    docker @baseArgs pull
    if ($LASTEXITCODE -ne 0) {
        exit $LASTEXITCODE
    }
}

docker @baseArgs up -d
exit $LASTEXITCODE
