<?php
/**
 * Version API endpoint
 * Returns system information, extension versions, and handles configuration updates.
 */

namespace IMATHUZH\Qfq\Api;

require_once(__DIR__ . '/../../vendor/autoload.php');

use IMATHUZH\Qfq\Core\Helper\Version;

// Detect API calls
define('QFQ_API', 'Api call');

$data = [];
$status = 200;

try {
    $result = Version::process();
    $data = $result[API_STORE_DATA_KEY];
    $status = $result[API_STATUS];

} catch (\Throwable $e) {
    $code = $e->getCode();
    $status = (is_int($code) && $code >= 100 && $code <= 599) ? $code : 500;
    $data = [API_ANSWER_STATUS_ERROR => $e->getMessage()];
}

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