<?php
require_once '../../includes/functions.php';
setCORSHeaders();

// Verify API Hash
verifyAPIHash();

if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
    sendError('Method not allowed', 405);
}

$productId = (int)($_GET['id'] ?? 0);

if ($productId <= 0) {
    sendError('Invalid product ID');
}

$stmt = $pdo->prepare("SELECT id, name, description, price_coins, min_order, image_url, category, coin_type, created_at FROM products WHERE id = ? AND is_active = 1");
$stmt->execute([$productId]);
$product = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$product) {
    sendError('Product not found', 404);
}

// Debug log
error_log("Product Detail API - Product ID: $productId");
error_log("Product Detail API - Found Product: " . json_encode($product));

sendResponse([
    'success' => true,
    'data' => $product
]);
?>
