# Quick build + test verification before commit-and-push.ps1.
#
# Run from the repo root:
#     pwsh -ExecutionPolicy Bypass -File .\build-and-test.ps1
#
# Builds TeamsISO.Windows.slnf in Release with TreatWarningsAsErrors=true
# (the Directory.Build.props default), then runs unit tests excluding the
# requires=ndi tier (those need a live NDI runtime).

$ErrorActionPreference = 'Stop'

if (-not (Test-Path 'TeamsISO.Windows.slnf')) {
    throw "Run from the TeamsISO repo root."
}

Write-Host "=== dotnet --version ===" -ForegroundColor Cyan
dotnet --version

Write-Host ""
Write-Host "=== Restore ===" -ForegroundColor Cyan
dotnet restore TeamsISO.Windows.slnf
if ($LASTEXITCODE -ne 0) { throw "Restore failed." }

Write-Host ""
Write-Host "=== Build (Release, TreatWarningsAsErrors=true) ===" -ForegroundColor Cyan
dotnet build TeamsISO.Windows.slnf --configuration Release --no-restore --nologo
if ($LASTEXITCODE -ne 0) {
    throw "Build failed. Most likely cause for this batch: System.Windows.Automation needs an explicit Reference. If so, add to src/TeamsISO.App/TeamsISO.App.csproj inside an <ItemGroup>: <Reference Include='UIAutomationClient' /> <Reference Include='UIAutomationTypes' />"
}

Write-Host ""
Write-Host "=== Tests (excluding requires=ndi) ===" -ForegroundColor Cyan
dotnet test TeamsISO.Windows.slnf `
    --configuration Release `
    --no-build `
    --nologo `
    --filter "Category!=ndi&requires!=ndi"
if ($LASTEXITCODE -ne 0) { throw "Tests failed." }

Write-Host ""
Write-Host "Build + tests green. Now run .\commit-and-push.ps1 to ship." -ForegroundColor Green
