<?php
require_once __DIR__ . '/config/database.php';
require_once __DIR__ . '/controllers/ProductController.php';

function sendSuccess($data = null, $message = '') {
    echo json_encode(['success' => true, 'data' => $data, 'message' => $message]);
    exit;
}

ob_start();
try {
    ProductController::trendingProducts();
} catch (Exception $e) {}
$output = ob_get_clean();

$data = json_decode($output, true);
if ($data && isset($data['data']['products'])) {
    echo "SUCCESS: Trending products included in response.\n";
    echo "Product count: " . count($data['data']['products']) . "\n";
    if (count($data['data']['products']) > 0) {
        echo "Example Product (ID: " . $data['data']['products'][0]['id'] . "): " . $data['data']['products'][0]['name'] . " (Discount: " . $data['data']['products'][0]['discount_percent'] . "%)\n";
    }
} else {
    echo "FAILURE: Trending products NOT included in response.\n";
    echo "Response: " . $output . "\n";
}
