<?php
// File: /v1/admin/error/error_list_last20.php
require_once __DIR__ . '/../../connect.php';

try {
    $sql = "SELECT `id`, `error`, `userId`, `userType`, `phone`, `created_at`, `device`, `details`, `status`
            FROM `error`
            ORDER BY `created_at` DESC
            LIMIT 20";
    $stmt = $con->prepare($sql);
    $stmt->execute();
    $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);

    jsonSuccess($rows);
} catch (Exception $e) {
    error_log("error_list_last20.php: " . $e->getMessage());
    jsonError($message = "Failed to fetch last 20 errors");
}