<#
.SYNOPSIS
Runs build_exe.py with the pinned Python 3.8.6 interpreter (per Context7 techContext requirements) inside PowerShell.

.DESCRIPTION
The script ensures the executable at D:/Local/dev/python/Python38-32/python.exe exists, validates its version (3.8.6), and then passes along all arguments to build_exe.py just as the cmd helper would. The logic mirrors the documented workflow in memory-bank/techContext.md#Build-Process which specifies PyInstaller builds using Python 3.8.

.NOTES
Context7 compliance: uses documented interpreter path/version and PyInstaller invocation from build_exe.py.
#>

$ErrorActionPreference = 'Stop'

$pythonExe = 'D:/Local/dev/python/Python38-32/python.exe'

if (-not (Test-Path $pythonExe)) {
    Write-Error "Python 3.8.6 executable not found at $pythonExe. Install 32-bit Python 3.8.6 or update this path."
    exit 1
}

$version = & "$pythonExe" -c "import platform; print(platform.python_version())" 2>$null

if (-not $version) {
    Write-Error "Unable to determine Python version from $pythonExe."
    exit 1
}

$version = $version.Trim()

if ($version -ne '3.8.6') {
    Write-Warning "Detected Python $version at $pythonExe. Context7 mandates 3.8.6 for Oracle compatibility."
}

Write-Host "Running build_exe.py with Python $version at $pythonExe"

& "$pythonExe" build_exe.py @args

if ($LASTEXITCODE -ne 0) {
    Write-Error "build_exe.py failed with exit code $LASTEXITCODE"
    exit $LASTEXITCODE
}

Write-Host "Build script completed successfully."
