$ErrorActionPreference = "Stop"

param(
  [int]$BaselineWindowHours = 0,
  [int]$StaleRefreshThresholdHours = 0,
  [int]$TopAccountTokens = 20,
  [int]$EntityLimit = 0,
  [string]$Output = "",
  [switch]$Strict
)

$EnvName = "ndc_1c_mvp"
$EnvPython = Join-Path $env:USERPROFILE "miniconda3\envs\$EnvName\python.exe"
if (-not (Test-Path $EnvPython)) {
  $EnvPython = Join-Path $env:USERPROFILE "Miniconda3\envs\$EnvName\python.exe"
}
if (-not (Test-Path $EnvPython)) {
  throw "Python for env '$EnvName' not found. Expected: $EnvPython"
}

$Args = @("scripts/run_features.py", "--top-account-tokens", $TopAccountTokens.ToString())
if ($BaselineWindowHours -gt 0) { $Args += @("--baseline-window-hours", $BaselineWindowHours.ToString()) }
if ($StaleRefreshThresholdHours -gt 0) { $Args += @("--stale-refresh-threshold-hours", $StaleRefreshThresholdHours.ToString()) }
if ($EntityLimit -gt 0) { $Args += @("--entity-limit", $EntityLimit.ToString()) }
if ($Output) { $Args += @("--output", $Output) }
if ($Strict) { $Args += "--strict" }

& $EnvPython @Args
exit $LASTEXITCODE
