<?php
require_once __DIR__ . '/../config/database.php';
require_once __DIR__ . '/../includes/helpers.php';

require_post();
$data = json_input();
require_fields($data, ['id']);

$pdo = getConnection();

try {
    $id = (int)$data['id'];
    $stmt = $pdo->prepare("DELETE FROM promociones WHERE id = ?");
    $stmt->execute([$id]);

    if ($stmt->rowCount() === 0) {
        json_error("Promocion no encontrada");
    } else {
        json_success([], 'Promocion eliminada');
    }
} catch (Exception $e) {
    json_error("Error: " . $e->getMessage());
}
