param(
    [Parameter(Mandatory = $true)] [string] $MtciDirectory,
    [Parameter(Mandatory = $true)] [string] $OutputPbf,
    [Parameter(Mandatory = $true)] [double] $West,
    [Parameter(Mandatory = $true)] [double] $South,
    [Parameter(Mandatory = $true)] [double] $East,
    [Parameter(Mandatory = $true)] [double] $North
)

$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:writeMtciPbf `
    "-PmtciDirectory=$MtciDirectory" `
    "-PpbfOutput=$OutputPbf" `
    "-PselectionWest=$West" `
    "-PselectionSouth=$South" `
    "-PselectionEast=$East" `
    "-PselectionNorth=$North"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
