# ReBreak Magic für Windows — Build-Script (auf einer Windows-Maschine ausführen)
#
# Voraussetzungen:
#   - Rust (rustup, MSVC toolchain)
#   - Node + pnpm (Repo-Root: pnpm install)
#   - WebView2 Runtime (Win11: vorinstalliert)
#
# Ergebnis: NSIS-Installer unter src-tauri\target\release\bundle\nsis\

$ErrorActionPreference = "Stop"
Set-Location $PSScriptRoot

# 1. Tamper-Service als Release bauen und als Tauri-Sidecar ablegen
#    (externalBin erwartet Suffix mit Target-Triple)
cargo build --release -p rebreak-protection-service --manifest-path src-tauri/Cargo.toml

$triple = (rustc -vV | Select-String "host: (.*)").Matches.Groups[1].Value
Copy-Item `
  "src-tauri/target/release/rebreak-protection-service.exe" `
  "src-tauri/binaries/rebreak-protection-service-$triple.exe" -Force

# 2. Frontend + Tauri-App + NSIS-Installer
pnpm tauri build

Write-Host ""
Write-Host "Fertig. Installer:" -ForegroundColor Green
Get-ChildItem "src-tauri/target/release/bundle/nsis/*.exe" | ForEach-Object { Write-Host "  $($_.FullName)" }
