<?php
declare(strict_types=1);
session_start();
require_once '../../config.php';
require_once __DIR__ . '/../helpers.php';
if (!isset($_SESSION['user_id'])) { http_response_code(401); echo json_encode(['success'=>false]); exit; }
header('Content-Type: application/json');
$conn = getDBConnection();
$paperId = (int) ($_POST['paper_id'] ?? 0);
$questionId = (int) ($_POST['question_id'] ?? 0);
if (!$conn instanceof mysqli || $paperId <= 0 || $questionId <= 0) { echo json_encode(['success'=>false,'message'=>'Invalid request']); exit; }
$stmt = $conn->prepare("DELETE FROM exam_paper_questions WHERE paper_id = ? AND question_id = ?");
$stmt->bind_param('ii', $paperId, $questionId);
$stmt->execute();
$stmt->close();
examsUpdatePaperTotalMarks($conn, $paperId);
echo json_encode(['success'=>true,'message'=>'Question removed from paper']);
