<?php
session_start();
header('Content-Type: application/json');

require_once '../../config/database.php';
require_once '../../includes/access_control.php';

// Check if user is logged in and is a teacher
require_teacher();

// Only allow POST requests
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    echo json_encode(['success' => false, 'message' => 'Invalid request method']);
    exit();
}

try {
    $question_id = (int)$_POST['question_id'];
    
    if ($question_id <= 0) {
        echo json_encode(['success' => false, 'message' => 'Invalid question ID']);
        exit();
    }
    
    // Delete the question
    $stmt = $pdo->prepare("DELETE FROM exam_questions WHERE id = ?");
    $stmt->execute([$question_id]);
    
    echo json_encode(['success' => true, 'message' => 'প্রশ্ন সফলভাবে মুছে ফেলা হয়েছে!']);
    
} catch (Exception $e) {
    echo json_encode(['success' => false, 'message' => 'প্রশ্ন মুছে ফেলতে সমস্যা হয়েছে: ' . $e->getMessage()]);
}