<#
.SYNOPSIS
  Собирает release-zip enroll-tool: скрипты + bundled adb + последний DPC APK.
.DESCRIPTION
  Использование перед публикацией на /downloads/komendant-enroll-usb.zip:
    cd enroll-tool
    .\build.ps1 -AndroidSdk 'C:\Android'
#>
param(
    [string]$AndroidSdk = 'C:\Android',
    [string]$DpcApk = '..\dpc-app\build\outputs\apk\release\dpc-app-release.apk',
    [string]$OutZip = '..\komendant-enroll-usb.zip'
)
$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $PSCommandPath
Push-Location $root

$platformTools = Join-Path $AndroidSdk 'platform-tools'
foreach ($f in 'adb.exe','AdbWinApi.dll','AdbWinUsbApi.dll') {
    Copy-Item -Path (Join-Path $platformTools $f) -Destination $root -Force
}
if (-not (Test-Path $DpcApk)) {
    Write-Error "DPC APK не найден: $DpcApk — сначала собери: .\gradlew :dpc-app:assembleRelease"
}
Copy-Item -Path $DpcApk -Destination (Join-Path $root 'komendant-dpc.apk') -Force

$abs = Resolve-Path $OutZip -ErrorAction SilentlyContinue
if ($abs) { Remove-Item $abs -Force }
Compress-Archive -Path 'enroll.ps1','enroll.cmd','README.md','adb.exe','AdbWinApi.dll','AdbWinUsbApi.dll','komendant-dpc.apk' -DestinationPath $OutZip -Force

Write-Host "OK: $(Resolve-Path $OutZip) ($([math]::Round((Get-Item (Resolve-Path $OutZip)).Length/1MB, 1)) MB)"
Pop-Location
