import { existsSync, readFileSync } from 'node:fs';
import { resolve } from 'node:path';
const root=resolve(import.meta.dirname,'..');
const files=['UPDATE_VENDOO.bat','scripts/update-vendoo-gui.ps1','scripts/update-vendoo.ps1','scripts/updater/Vendoo.Updater.UI.ps1','scripts/updater/Vendoo.Updater.Worker.ps1','docs/PRODUCTION_UPDATER_2_0.md'];
const failures=[];for(const f of files)if(!existsSync(resolve(root,f)))failures.push(`Pflichtdatei fehlt: ${f}`);
const read=f=>readFileSync(resolve(root,f),'utf8');const bat=read(files[0]),ui=read(files[3]),worker=read(files[4]),docs=read(files[5]);
const must=(text,t,label)=>{if(!text.includes(t))failures.push(`${label} fehlt: ${t}`)};
for(const t of ['WindowStyle Hidden','update-vendoo-gui.ps1'])must(bat,t,'Starter');
for(const t of ['Vendoo Production Updater','Update-Ablauf','Technisches Protokoll','Erneut versuchen','Fehler kopieren','ClosingAllowed','Updater-Prozess unerwartet beendet','PasswordBox','DispatcherTimer'])must(ui,t,'WPF-Oberfläche');
for(const t of ["$UpdaterVersion='2.0.0'",'Vendoo\\Updater','api.github.com/repos/cli/cli/releases/latest','_checksums.txt','Get-FileHash','SHA-256','Invoke-External','TimeoutSeconds','Stop-Tree','OperationCanceledException','Request-Secret','RedirectStandardInput','Save-Session','Load-Session','runId','Check-ProductionVersion','verify:all'])must(worker,t,'Worker');
for(const forbidden of ['winget.exe','UPDATE_VENDOO.bat bitte erneut starten','Start-Transcript'])if(worker.includes(forbidden))failures.push(`Verbotene Altlogik im Worker: ${forbidden}`);
for(const f of [files[1],files[2],files[3],files[4]]){const b=readFileSync(resolve(root,f));if(!(b[0]===0xef&&b[1]===0xbb&&b[2]===0xbf))failures.push(`${f} besitzt keine UTF-8-BOM.`)}
for(const t of ['Fenster bleibt','Wiederaufnahmepunkt','SHA-256'])must(docs,t,'Dokumentation');
if(failures.length){console.error(`Production-Updater-2.0-Gate fehlgeschlagen (${failures.length})`);for(const f of failures)console.error(`- ${f}`);process.exit(1)}
console.log('OK: Vendoo Production Updater 2.0 – WPF, persistente Fehleranzeige, portable verifizierte GitHub CLI, Timeouts, Abbruch und Wiederaufnahme.');
