# Compile SirayaPrinterSetup.exe (requires Inno Setup 6 on Windows).
param(
  [string]$Version = "2.0.0",
  [string]$PayloadRoot = "",
  [string]$OutputDir = ""
)

$ErrorActionPreference = "Stop"
$Root = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent

if (-not $PayloadRoot) {
  $PayloadRoot = Join-Path $Root "dist\release\payload\win-x64"
}
if (-not $OutputDir) {
  $OutputDir = Join-Path $Root "dist\release"
}

if (-not (Test-Path (Join-Path $PayloadRoot "app\index.js"))) {
  throw "Payload missing. Run: npm run build:release"
}

$iscc = "${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe"
if (-not (Test-Path $iscc)) {
  $iscc = "${env:ProgramFiles}\Inno Setup 6\ISCC.exe"
}
if (-not (Test-Path $iscc)) {
  throw "Inno Setup 6 not found. Install from https://jrsoftware.org/isinfo.php"
}

$iss = Join-Path $PSScriptRoot "inno\SirayaPrinterSetup.iss"
& $iscc /DAppVersion=$Version /DPayloadRoot=$PayloadRoot /DOutputDir=$OutputDir $iss
Write-Host "Built: $(Join-Path $OutputDir 'SirayaPrinterSetup.exe')"
