param(
    [switch]$AsJson
)

$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest

$proj = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $proj | Out-Null

$outDir = Join-Path $proj 'out'
New-Item -ItemType Directory -Force -Path $outDir | Out-Null

$dataPath = Join-Path $proj 'demo-data.json'
$raw = Get-Content -Path $dataPath -Raw -Encoding UTF8
$demo = $raw | ConvertFrom-Json

$payload = [ordered]@{
    app = 'asset-audit-console-c'
    name = 'Asset Audit Console C'
    language = 'C'
    stack = 'C (gcc), Native Source, PowerShell WinForms App'
    status = 'ok'
    generatedAt = (Get-Date).ToString('yyyy-MM-dd HH:mm:ss')
    appType = 'PowerShell WinForms App'
    sourceFile = 'src/main.c'
    sourceHint = 'gcc .\src\main.c -O2 -o .\out\asset_audit_c.exe && .\out\asset_audit_c.exe'
    summary = $demo.summary
    items = $demo.items
    notes = $demo.notes
}

$json = $payload | ConvertTo-Json -Depth 8
Set-Content -Path (Join-Path $outDir 'last-demo.json') -Value $json -Encoding UTF8
Write-Output $json
exit 0
