$ErrorActionPreference = "Stop"

param(
  [string]$SourceFeatureRunId = "",
  [int]$AnomalyLimit = 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_risk.py")
if ($SourceFeatureRunId) { $Args += @("--source-feature-run-id", $SourceFeatureRunId) }
if ($AnomalyLimit -gt 0) { $Args += @("--anomaly-limit", $AnomalyLimit.ToString()) }
if ($Output) { $Args += @("--output", $Output) }
if ($Strict) { $Args += "--strict" }

& $EnvPython @Args
exit $LASTEXITCODE
