<?php
/**
 * POST /api/admin/ads_delete.php
 * Admin-only. Body (JSON): { id }
 */

require_once __DIR__ . '/../config/database.php';
require_once __DIR__ . '/../includes/response.php';
require_once __DIR__ . '/../includes/auth.php';

only_post_allowed();
require_login();
require_role(['admin']);

$input = get_json_input();
$id = (int) ($input['id'] ?? 0);
if ($id <= 0) {
    send_error('A valid ad id is required.', 422);
}

$pdo = Database::connect();
$stmt = $pdo->prepare('DELETE FROM ad_placements WHERE id = ?');
$stmt->execute([$id]);

send_json(true, 'Ad deleted.');
