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

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

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