<?php
header('Content-Type: application/json');
// Buscar config.php en rutas posibles
$paths = [
    __DIR__ . '/config.php',
    __DIR__ . '/../config.php',
    __DIR__ . '/../../config.php',
    '/home/wwsist/public_html/app-api/config.php',
];
$loaded = false;
foreach ($paths as $p) {
    if (file_exists($p)) {
        require_once $p;
        $loaded = $p;
        break;
    }
}
if (!$loaded) { echo json_encode(['error' => 'config not found']); exit; }

try {
    $stmt = $pdo->query("DESCRIBE regs2");
    $cols = $stmt->fetchAll(PDO::FETCH_ASSOC);
    $stmt2 = $pdo->query("SELECT * FROM regs2 ORDER BY idreg DESC LIMIT 1");
    $sample = $stmt2->fetchAll(PDO::FETCH_ASSOC);
    echo json_encode(['config' => $loaded, 'columns' => $cols, 'sample' => $sample], JSON_PRETTY_PRINT);
} catch (Exception $e) {
    echo json_encode(['error' => $e->getMessage(), 'config' => $loaded]);
}
