<?php
require_once __DIR__ . '/../config/db_auto.php';
header('Content-Type: application/json');

$run = trim($_GET['run'] ?? '');

if (empty($run)) {
    echo json_encode(['existe' => false, 'error' => 'RUN no proporcionado.']);
    exit;
}

try {
    $stmt = $pdo->prepare('SELECT COUNT(*) FROM alumnos WHERE run = ?');
    $stmt->execute([$run]);
    $count = $stmt->fetchColumn();

    echo json_encode(['existe' => $count > 0]);
} catch (Exception $e) {
    http_response_code(500);
    echo json_encode(['existe' => false, 'error' => 'Error en la consulta a la base de datos.']);
}
