# Ensures client firebase-config.js matches PHP bootstrap (arafstore-14938).
$ErrorActionPreference = 'Stop'
$root = Split-Path $PSScriptRoot -Parent

$jsPath = Join-Path $root 'firebase-config.js'
$bootPaths = @(
    (Join-Path $root 'api\firebase-admin-bootstrap.local.php'),
    (Join-Path $root 'super-admin-panel\api\firebase-admin-bootstrap.local.php')
)

$js = Get-Content $jsPath -Raw
$expected = @{
    projectId = 'arafstore-14938'
    databaseURL = 'https://arafstore-14938-default-rtdb.firebaseio.com'
    apiKey = 'AIzaSyCqfdaLceRPWxi7PQ6QJyrqbSLudoMUywI'
}

$fail = 0
foreach ($k in $expected.Keys) {
    if ($js -notmatch [regex]::Escape($expected[$k])) {
        Write-Host "FAIL firebase-config.js missing $k = $($expected[$k])" -ForegroundColor Red
        $fail++
    }
}

foreach ($bp in $bootPaths) {
    if (-not (Test-Path $bp)) {
        Write-Host "FAIL missing bootstrap: $bp" -ForegroundColor Red
        $fail++
        continue
    }
    $content = Get-Content $bp -Raw
    if ($content -notmatch [regex]::Escape($expected.databaseURL)) {
        Write-Host "FAIL database URL mismatch in $bp" -ForegroundColor Red
        $fail++
    }
    if ($content -notmatch [regex]::Escape($expected.apiKey)) {
        Write-Host "FAIL apiKey mismatch in $bp" -ForegroundColor Red
        $fail++
    } else {
        Write-Host "OK $bp" -ForegroundColor Green
    }
}

if ($fail -gt 0) { exit 1 }
Write-Host "Client config and PHP bootstrap are consistent for arafstore-14938."
