<?php

declare(strict_types=1);

require __DIR__.'/../src/warmup.php';

$data          = new stdClass();
$data->status  = 'success';
$data->stats   = [];
$data->reindex = $_SESSION['cin_ajax_search_reindex'] ?? null;

try {
  $data->stats = Cin\Quickpurchase\Index::statAll();
} catch (Throwable) {
  $data->status  = 'error';
  $data->message = 'Indexstatistik konnte nicht geladen werden.';
  $data->stats   = [
    'total' => [
      'documentCount'                => 0,
      'documentCountAcrossLanguages' => 0,
      'fileSize'                     => 0
    ]
  ];
}

header('Content-Type: application/json');
echo json_encode($data);
