<?php
include 'db_connection.php';

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

$requestPayload = json_decode(file_get_contents('php://input'), true);
$grade_id = isset($requestPayload['grade_id']) ? (int)$requestPayload['grade_id'] : null;

if (!$grade_id) {
    echo json_encode(['success' => false, 'message' => 'Grade ID is required.']);
    exit();
}

try {
    $stmt = $pdo->prepare("DELETE FROM grades WHERE id = :grade_id");
    $stmt->bindParam(':grade_id', $grade_id, PDO::PARAM_INT);
    $stmt->execute();

    echo json_encode(['success' => true, 'message' => 'Grade deleted successfully.']);
} catch (PDOException $e) {
    echo json_encode(['success' => false, 'message' => 'Database error: ' . $e->getMessage()]);
}
?>
