<?php
// Diagnóstico KYC - sin autenticación
header('Content-Type: application/json');

$results = [];

// 1. Verificar ruta del config
$configPath1 = dirname(__FILE__) . '/../config.php';
$configPath2 = dirname(__FILE__) . '/../../config.php';
$results['config_path1'] = $configPath1;
$results['config_path1_exists'] = file_exists($configPath1);
$results['config_path2'] = $configPath2;
$results['config_path2_exists'] = file_exists($configPath2);

// 2. Verificar directorio uploads
$uploadBase = dirname(__FILE__) . '/../uploads/';
$results['uploads_dir'] = $uploadBase;
$results['uploads_exists'] = is_dir($uploadBase);
$results['uploads_writable'] = is_writable($uploadBase);

// 3. Verificar directorio kyc
$kycDir = $uploadBase . 'kyc/';
$results['kyc_dir_exists'] = is_dir($kycDir);
if (!is_dir($kycDir)) {
    $created = mkdir($kycDir, 0755, true);
    $results['kyc_dir_created'] = $created;
}
$results['kyc_dir_writable'] = is_writable($kycDir);

// 4. Verificar si la tabla archivo existe
if (file_exists($configPath1)) {
    require_once $configPath1;
    try {
        $db = getDB();
        $stmt = $db->query("DESCRIBE archivo");
        $cols = $stmt->fetchAll(PDO::FETCH_COLUMN);
        $results['tabla_archivo_cols'] = $cols;
    } catch (Throwable $e) {
        $results['tabla_archivo_error'] = $e->getMessage();
    }
}

echo json_encode($results, JSON_PRETTY_PRINT);
