<?php
$root = dirname(__DIR__);
$version = json_decode(file_get_contents($root . '/DDB_VERSION.json'), true);
$css = file_get_contents($root . '/public/assets/css/executive-ui-core.css');

$checks = [
    'version' => ($version['version'] ?? '') === '11.0.11.67',
    'phase' => ($version['phase'] ?? '') === 'H11.0-P11.1-R45-P4.1.1',
    'desktop_edge_padding' => strpos($css, 'padding: 26px 32px 25px !important') !== false,
    'notice_edge_inset' => strpos($css, 'width: calc(100% - 4px)') !== false,
    'filter_edge_inset' => strpos($css, '.eri-r45p1-filter-grid {') !== false
        && strpos($css, 'padding-inline: 2px') !== false,
    'tablet_edge_padding' => strpos($css, 'padding: 23px 25px 22px !important') !== false,
    'mobile_edge_padding' => strpos($css, 'padding: 19px 17px 18px !important') !== false,
    'oracle_unchanged' => ($version['r45_p4_1_1']['oracle_writes'] ?? '') === 'NONE',
];

$failed = [];
foreach ($checks as $name => $ok) {
    if (!$ok) $failed[] = $name;
}
echo json_encode([
    'schema' => 'R45_P4_1_1_QA',
    'checks' => $checks,
    'passed' => count($checks) - count($failed),
    'failed' => $failed
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;
exit(count($failed) === 0 ? 0 : 1);
