#requires -Version 5.1
<#
.SYNOPSIS
  One-shot pilot shipment prep: migrate, seed facts, backup, assess readiness.
.EXAMPLE
  .\scripts\ship-pilot-ready.ps1 -SqlServer localhost
#>
[CmdletBinding()]
param(
  [string]$SqlServer = 'localhost',
  [string]$Database = 'SovereignRepository'
)

$ErrorActionPreference = 'Stop'
$repoRoot = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
Set-Location $repoRoot

Write-Host '=== Ship pilot ready ===' -ForegroundColor Cyan
Write-Host '[1/4] npm run migrate'
npm run migrate
if ($LASTEXITCODE -ne 0) { throw 'migrate failed' }

Write-Host '[2/4] Backup SovereignRepository'
& (Join-Path $repoRoot 'scripts\Backup-SovereignRepository.ps1') -SqlServer $SqlServer -Database $Database

Write-Host '[3/4] Quality gates'
npm run verify:quality
if ($LASTEXITCODE -ne 0) { throw 'verify:quality failed' }

Write-Host '[4/4] Shipment readiness assessment'
& (Join-Path $repoRoot 'Assess-ShipmentReadiness.ps1') -SqlServer $SqlServer -Database $Database -RepoRoot $repoRoot

Write-Host ''
Write-Host 'Next: complete first-run setup at http://localhost:3000/setup' -ForegroundColor Green
