<?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 (isset($_GET['id'])) {
    $training_id = $_GET['id'];

    // Get the training
    $stmt = $pdo->prepare("SELECT * FROM graduate_trainings WHERE id = ? AND graduate_id = (SELECT id FROM graduates WHERE user_id = ?)");
    $stmt->execute([$training_id, $user['id']]);
    $training = $stmt->fetch();

    if ($training) {
        echo json_encode(['success' => true, 'training' => $training]);
    } else {
        echo json_encode(['success' => false, 'message' => 'Training not found']);
    }
} else {
    echo json_encode(['success' => false, 'message' => 'Invalid request']);
}
?>