param(
    [Parameter(Mandatory = $true)][string]$CombinedRoot,
    [Parameter(Mandatory = $true)][string]$Output,
    [Parameter(Mandatory = $true)][double]$HeadingOffsetDeg,
    [Parameter(Mandatory = $true)][double[]]$AntennaLever,
    [int]$MinStations = 30,
    [int]$ExpectedStations = 0,
    [double]$HeadingStdLimitDeg = 0.5,
    [switch]$Overwrite
)

$ErrorActionPreference = "Stop"
if ($AntennaLever.Count -ne 3) { throw "AntennaLever must contain X,Y,Z in body coordinates" }
$Repo = Split-Path -Parent $PSScriptRoot
$Args = @((Join-Path $Repo "tools\prepare_multisensor_station_dataset.py"), "--combined-root", $CombinedRoot,
    "--output", $Output, "--heading-offset-deg", "$HeadingOffsetDeg", "--antenna-lever") +
    @($AntennaLever | ForEach-Object { "$_" }) + @("--min-stations", "$MinStations",
    "--expected-stations", "$ExpectedStations", "--heading-std-limit-deg", "$HeadingStdLimitDeg")
if ($Overwrite) { $Args += "--overwrite" }
& python @Args
if ($LASTEXITCODE -ne 0) { throw "Multisensor dataset preparation failed" }
