[CmdletBinding()]
param([string]$Manifest)

$ErrorActionPreference = 'Stop'
if ([string]::IsNullOrWhiteSpace($Manifest)) {
  $scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
  $Manifest = Join-Path $scriptRoot '..\manifests\m1-dependencies.json'
}
$lock = Get-Content -LiteralPath $Manifest -Raw | ConvertFrom-Json
$failures = [System.Collections.Generic.List[string]]::new()
foreach ($dependency in $lock.dependencies) {
  if ([string]::IsNullOrWhiteSpace([string]$dependency.revision)) { $failures.Add("$($dependency.name): immutable revision missing") }
  if ([string]::IsNullOrWhiteSpace([string]$dependency.archiveSha256)) { $failures.Add("$($dependency.name): archiveSha256 missing") }
}
if ($failures.Count -gt 0) { Write-Error ("M1 dependency lock is not release-ready:" + [Environment]::NewLine + " - " + ($failures -join ([Environment]::NewLine + " - "))); exit 2 }
Write-Output "M1 dependency lock verified: $($lock.dependencies.Count) dependencies"
