<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

header('Content-Type: application/json');

require_once __DIR__ . '/../config/database.php';

$question_id = $_POST['question_id'] ?? '';

if (empty($question_id)) {
    echo json_encode([
        'status' => 'error',
        'message' => 'Missing question ID.'
    ]);
    exit;
}

try {
    $sql = "DELETE FROM questions WHERE id = :question_id";
    $stmt = $pdo->prepare($sql);
    $stmt->execute([
        'question_id' => $question_id
    ]);

    echo json_encode([
        'status' => 'success',
        'message' => 'Question deleted.',
        'rows_deleted' => $stmt->rowCount(),
        'question_id' => $question_id
    ]);
} catch (Throwable $e) {
    echo json_encode([
        'status' => 'error',
        'message' => $e->getMessage()
    ]);
}