<?php
session_start();
require_once(__DIR__ . '/../db/conexion.php');
header('Content-Type: application/json; charset=utf-8');

$response = ['success' => false];

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;

if ($id <= 0) {
    $response['message'] = 'ID inválido';
    echo json_encode($response);
    exit;
}

$stmt = $conn->prepare("
    SELECT vacante_codigo, vacante_puesto, vacante_pdv
    FROM aspirantes
    WHERE id = ?
");

if ($stmt) {
    $stmt->bind_param("i", $id);
    $stmt->execute();
    $res = $stmt->get_result();

    if ($res->num_rows > 0) {
        $row = $res->fetch_assoc();
        $response['success'] = true;
        $response['data'] = $row;
    } else {
        $response['message'] = 'Aspirante no encontrado';
    }
} else {
    $response['message'] = 'Error en la consulta';
}

echo json_encode($response);
