# Build staging folder for WiX MSI packaging (run on Windows CI or dev machine).
param(
  [string]$Version = "2.0.0",
  [string]$NodeZipUrl = "https://nodejs.org/dist/v20.19.5/node-v20.19.5-win-x64.zip"
)

$ErrorActionPreference = "Stop"
$Root = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent
$Stage = Join-Path $Root "dist\msi-stage"
$PayloadDir = $Stage

. (Join-Path $PSScriptRoot "Build-Payload.ps1")

Build-WindowsPayload -Root $Root -PayloadDir $PayloadDir -Version $Version -Arch "win-x64" -NodeZipUrl $NodeZipUrl

# Legacy layout: dist/msi-stage/app + dist/msi-stage/runtime
$AppDir = Join-Path $Stage "app"
$RuntimeDir = Join-Path $Stage "runtime"

@"
# Siraya Printer MSI stage
version=$Version
app=$AppDir
runtime=$RuntimeDir

Next: compile installer/windows/wix/Product.wxs with WiX v4 + sign with signtool.
"@ | Set-Content (Join-Path $Stage "README-STAGE.txt")

Write-Host "MSI stage ready at $Stage"
