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

$promo_code = filterRequest("promo_code");

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

$stmt = $con->prepare($sql);
$stmt->bindParam(':promo_code', $promo_code, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);

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