<?php

declare(strict_types=1);

require_once dirname(__DIR__) . '/app/bootstrap.php';

use App\Repositories\InpatientDailyRevenueRepository;

$started = microtime(true);
$result = [
    'phase' => 'H11.0-P10.4-R3',
    'title' => 'Inpatient Daily Revenue Live Oracle Contract Smoke Gate',
    'hospital' => 'njch',
    'mode' => 'READ_ONLY_ZERO_ROW_SCHEMA_VALIDATION',
    'oracle_writes' => 'NONE',
    'status' => 'FAIL',
    'elapsed_ms' => 0,
    'message' => '',
];

try {
    $repository = new InpatientDailyRevenueRepository('njch');
    $repository->validateOracleContract();
    $result['status'] = 'PASS';
    $result['message'] = 'Oracle accepted the complete daily revenue SQL contract; zero patient rows were requested.';
} catch (Throwable $e) {
    $result['status'] = 'FAIL';
    $result['message'] = $e->getMessage();
    $result['exception'] = get_class($e);
}

$result['elapsed_ms'] = (int)round((microtime(true) - $started) * 1000);

echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), PHP_EOL;
exit($result['status'] === 'PASS' ? 0 : 1);
