<?php
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
require_once '../includes/db.php';
require_once '../includes/auth.php';

check_role('egresado');

$user = get_logged_in_user();

if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['notification_id'])) {
    $notification_id = $_POST['notification_id'];
    $title = trim($_POST['title']);
    $message = trim($_POST['message']);
    $type = $_POST['type'];

    // Update the notification
    $stmt = $pdo->prepare("UPDATE notifications SET title = ?, message = ?, type = ? WHERE id = ? AND user_id = ?");
    $stmt->execute([$title, $message, $type, $notification_id, $user['id']]);

    // Return success response
    echo json_encode(['success' => true]);
} else {
    echo json_encode(['success' => false, 'message' => 'Invalid request']);
}
?>