param(
    [Parameter(Mandatory = $true)]
    [string] $PbfFile,
    [Parameter(Mandatory = $true)]
    [string] $OutputDirectory,
    [int] $Shards = 64,
    [int] $Threads = [Math]::Max(1, [Math]::Min(16, [Environment]::ProcessorCount - 1))
)

$ErrorActionPreference = "Stop"
$projectRoot = Split-Path -Parent $PSScriptRoot
$applicationDir = Join-Path $projectRoot "application"
$env:GRADLE_USER_HOME = Join-Path $projectRoot ".gradle-user"

& (Join-Path $applicationDir "gradlew.bat") -p $applicationDir `
    --project-cache-dir (Join-Path $projectRoot ".gradle-project-cache") `
    '-Pmaptools.buildRoot=../build-windows' `
    :core:buildMtci `
    "-PpbfFile=$PbfFile" `
    "-PmtciOutput=$OutputDirectory" `
    "-PmtciShards=$Shards" `
    "-PmtciThreads=$Threads"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
