param(
    [string]$InputZip = "nuget-cache-export.zip"
)

$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
$inputPath = if ([System.IO.Path]::IsPathRooted($InputZip)) { $InputZip } else { Join-Path $repoRoot $InputZip }

if (-not (Test-Path $inputPath)) {
    Write-Error "Input zip not found: $inputPath"
    exit 1
}

Write-Host "Importing cache from: $inputPath"
Expand-Archive -Path $inputPath -DestinationPath $repoRoot -Force

Write-Host "Running restore with local cache..."
& (Join-Path $PSScriptRoot "dotnet-min.ps1") restore "Journal.Sidecar/Journal.Sidecar.csproj"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
& (Join-Path $PSScriptRoot "dotnet-min.ps1") restore "Journal.WebGateway/Journal.WebGateway.csproj"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
& (Join-Path $PSScriptRoot "dotnet-min.ps1") restore "Journal.SmokeTests/Journal.SmokeTests.csproj"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

Write-Host "Cache import complete."

