param(
    [string]$Source = "$(Split-Path -Parent $PSScriptRoot)\workflows\MiniMax_H3_Direct_2K_Experimental.json",
    [string]$Destination = "$(Split-Path -Parent $PSScriptRoot)\workflows\MiniMax_H3_736p_Maxine_Source.json"
)

$ErrorActionPreference = 'Stop'
$workflow = Get-Content -Raw -Encoding UTF8 -LiteralPath $Source | ConvertFrom-Json

$saveNode = $workflow.nodes | Where-Object { $_.id -eq 92 }
$resolutionNode = $workflow.nodes | Where-Object { $_.id -eq 115 }
$h3Node = $workflow.nodes | Where-Object { $_.id -eq 105 }
$noteNode = $workflow.nodes | Where-Object { $_.id -eq 116 }

if (-not $saveNode -or -not $resolutionNode -or -not $h3Node -or -not $noteNode) {
    throw 'The source workflow layout changed; expected nodes 92, 105, 115 and 116.'
}

$saveNode.widgets_values[0] = 'video/H3_736p_Maxine_Source'
$resolutionNode.title = 'H3 Native 736p for NVIDIA Maxine 1.5x'
$resolutionNode.widgets_values[0] = '16:9 (Widescreen)'
$resolutionNode.widgets_values[1] = 0.9
$resolutionNode.widgets_values[2] = 32
$h3Node.widgets_values[1] = 1280
$h3Node.widgets_values[2] = 736
$h3Node.widgets_values[3] = 0.5
$noteNode.widgets_values = @(
    "## H3 736p + NVIDIA Maxine 1.5x`n`nThis workflow renders **1280x736** with the open H3-Base model. After H3 finishes and releases VRAM, run ``run_maxine_2k.cmd`` on the saved MP4. Maxine produces **1920x1104** at 1.5x, then the post-process crops 8 pixels from the top and bottom to export **1920x1088**. The default 0.5-second setting is a smoke test; increase duration only after the full chain succeeds."
)

$json = $workflow | ConvertTo-Json -Depth 100
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText($Destination, $json, $utf8NoBom)
Write-Output $Destination
