<?php

use classes\economic_v2_versioning_service;

if (!defined('WD')) {
    exit;
}

echo '[' . date('Y-m-d H:i:s') . '][ECONOMIC_V2] Starting best-effort history backfill' . PHP_EOL;

try {
    $report = (new economic_v2_versioning_service())->runBestEffortBackfill();
    echo json_encode(
        [
            'success' => true,
            'report' => $report,
        ],
        JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT
    ) . PHP_EOL;
} catch (\Throwable $e) {
    echo json_encode(
        [
            'success' => false,
            'error' => $e->getMessage(),
        ],
        JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT
    ) . PHP_EOL;
    throw $e;
}

echo '[' . date('Y-m-d H:i:s') . '][ECONOMIC_V2] Finished best-effort history backfill' . PHP_EOL;
