<?php
require_once __DIR__ . '/../../connect.php';

// Get passengerID and encrypt it only if هو رقم مشفر (إذا لزم الأمر)
// $passengerID = $encryptionHelper->encryptData(filterRequest("passengerID"));
$passengerID = filterRequest("passengerID"); // استخدم هذا إذا ID رقم فقط

$sql = "SELECT
    `id`,
    `promo_code`,
    `amount`,
    `description`,
    `validity_start_date`,
    `validity_end_date`
FROM
    `promos`
WHERE
    `passengerID` = ? AND CURDATE() BETWEEN validity_start_date AND validity_end_date";

$stmt = $con->prepare($sql);
$stmt->bindParam(1, $passengerID);
$stmt->execute();

$result = $stmt->fetchAll(PDO::FETCH_ASSOC);

if ($result) {
    jsonSuccess($result);
} else {
    jsonError("Failed to retrieve promo records");
}
?>