<?php
session_start();
require_once 'includes/database.php';
require_once 'Classes/Timetable.php';

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

if(!isset($_SESSION['username'])) {
    echo json_encode(['success' => false, 'message' => 'Unauthorized']);
    exit();
}

if(!isset($_POST['entry_id'])) {
    echo json_encode(['success' => false, 'message' => 'Entry ID required']);
    exit();
}

$timetable = new Timetable();
$entryId = $_POST['entry_id'];

try {
    if($timetable->deleteTimetableEntry($entryId)) {
        echo json_encode(['success' => true, 'message' => 'Entry deleted successfully']);
    } else {
        echo json_encode(['success' => false, 'message' => 'Failed to delete entry']);
    }
} catch(Exception $e) {
    echo json_encode([
        'success' => false,
        'message' => 'Database error: ' . $e->getMessage()
    ]);
}