<?php
require_once 'config.php';
checkAccess(['programmer']);

try {
    $sizeQuery = $pdo->query("SELECT (data_length + index_length) / 1024 AS size_kb 
                              FROM information_schema.TABLES 
                              WHERE table_schema = '$db' AND table_name = 'system_logs'");
    $size = $sizeQuery->fetch();
    
    $countQuery = $pdo->query("SELECT COUNT(*) as total FROM system_logs");
    $count = $countQuery->fetch();

    response([
        "sizeKb" => (float)($size['size_kb'] ?? 0),
        "recordCount" => (int)($count['total'] ?? 0),
        "isCritical" => ($size['size_kb'] > 50 * 1024)
    ]);
} catch (PDOException $e) {
    response(["error" => $e->getMessage()], 500);
}
?>