<?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['data'];
    $status = $result['status'];

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

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