# Build script for Windows release binary

$ErrorActionPreference = "Stop"

Write-Host "Building Markle for Windows..." -ForegroundColor Cyan

# Navigate to project root
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location "$scriptPath\.."

# Ensure Windows icon exists
if (-not (Test-Path "Assets\AppIcon.ico")) {
    Write-Host "Warning: AppIcon.ico not found. Application will use default icon." -ForegroundColor Yellow
    Write-Host "Run 'bash deploy/create-windows-icon.sh' on macOS/Linux to create the icon." -ForegroundColor Yellow
}

# Clean previous builds
Write-Host "Cleaning previous builds..." -ForegroundColor Yellow
dotnet clean MarkdownEditor.csproj -c Release

# Build for Windows x64
Write-Host "Building for Windows x64..." -ForegroundColor Yellow
dotnet publish MarkdownEditor.csproj `
    -c Release `
    -r win-x64 `
    --self-contained true `
    -p:PublishSingleFile=true `
    -p:IncludeNativeLibrariesForSelfExtract=true `
    -o .\bin\Release\win-x64

Write-Host ""
Write-Host "✓ Build completed successfully!" -ForegroundColor Green
Write-Host "Application: .\bin\Release\win-x64\OrmentiaMarkle.exe" -ForegroundColor Green
Write-Host ""
Write-Host "You can now:" -ForegroundColor Cyan
Write-Host "  1. Run the .exe file directly" -ForegroundColor Cyan
Write-Host "  2. Copy it to Program Files" -ForegroundColor Cyan
Write-Host "  3. Distribute the .exe file" -ForegroundColor Cyan
Write-Host ""

# Open File Explorer to the build location
Invoke-Item .\bin\Release\win-x64

