<?php
require_once '../../config/database.php';

try {
    $database = new Database();
    $conn = $database->getConnection();

    // Insert the testimonial provided by the user
    $stmt = $conn->prepare("INSERT INTO reviews (user_id, product_id, rating, comment, is_approved, is_visible) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE comment = VALUES(comment), rating = VALUES(rating), is_approved = VALUES(is_approved), is_visible = VALUES(is_visible)");
    $stmt->execute([
        4, // user_id - سارة حسن
        1, // product_id - first product
        5, // rating
        'منتجات رائعة جداً! البشرة أصبحت أكثر نعومة وإشراقاً. أنصح بها بشدة لكل الفتيات.', // comment
        1, // is_approved
        1  // is_visible
    ]);

    echo "تم إضافة التقييم بنجاح!";
} catch(PDOException $e) {
    echo "خطأ: " . $e->getMessage();
}
?>