# Copy Android device handoff doc (Unicode-safe; no Chinese in .bat)
param(
    [Parameter(Mandatory = $true)][string]$Root,
    [Parameter(Mandatory = $true)][string]$Ver
)

$docs = Join-Path $Root 'docs'
$rel  = Join-Path $Root 'firmware\release'

if (-not (Test-Path -LiteralPath $docs)) {
    Write-Host "  WARN: missing docs folder"
    exit 1
}

# Match: Android*_vX.Y.Z.md (ASCII regex only; avoids .bat GBK / .ps1 encoding issues)
$all = Get-ChildItem -LiteralPath $docs -Filter '*.md' -ErrorAction SilentlyContinue |
    Where-Object { $_.Name -match '^Android.+_v[0-9]+(\.[0-9]+)*\.md$' }

if (-not $all) {
    Write-Host "  WARN: no Android device doc in docs (Android*_v*.md)"
    exit 1
}

$exact = $all | Where-Object { $_.Name -like "*_v$Ver.md" } | Select-Object -First 1
if (-not $exact) {
    $src = $all | Sort-Object Name -Descending | Select-Object -First 1
    Write-Host "  NOTE: no *_v$Ver.md, using $($src.Name)"
} else {
    $src = $exact
}

Copy-Item -LiteralPath $src.FullName (Join-Path $rel $src.Name) -Force
Write-Host "  docs -> release\$($src.Name)"
exit 0
