<?php
echo "<h2>🔍 Verificando Estrutura da Tabela solicitacoes_rotas</h2>";

require_once 'conexao.php';

try {
    // Verificar estrutura da tabela
    $sql = "DESCRIBE solicitacoes_rotas";
    $stmt = $pdo->prepare($sql);
    $stmt->execute();
    $colunas = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo "<h3>Estrutura da tabela solicitacoes_rotas:</h3>";
    echo "<table border='1' style='border-collapse: collapse; width: 100%;'>";
    echo "<tr style='background-color: #f0f0f0;'>";
    echo "<th>Campo</th>";
    echo "<th>Tipo</th>";
    echo "<th>Null</th>";
    echo "<th>Key</th>";
    echo "<th>Default</th>";
    echo "<th>Extra</th>";
    echo "</tr>";
    
    foreach ($colunas as $coluna) {
        echo "<tr>";
        echo "<td><strong>{$coluna['Field']}</strong></td>";
        echo "<td>{$coluna['Type']}</td>";
        echo "<td>{$coluna['Null']}</td>";
        echo "<td>{$coluna['Key']}</td>";
        echo "<td>{$coluna['Default']}</td>";
        echo "<td>{$coluna['Extra']}</td>";
        echo "</tr>";
    }
    echo "</table>";
    
    // Verificar algumas rotas existentes
    echo "<h3>Exemplo de rotas existentes:</h3>";
    $sqlRotas = "SELECT id, titulo, status, created_at, updated_at FROM solicitacoes_rotas ORDER BY id DESC LIMIT 5";
    $stmtRotas = $pdo->prepare($sqlRotas);
    $stmtRotas->execute();
    $rotas = $stmtRotas->fetchAll(PDO::FETCH_ASSOC);
    
    if (count($rotas) > 0) {
        echo "<table border='1' style='border-collapse: collapse; width: 100%;'>";
        echo "<tr style='background-color: #f0f0f0;'>";
        echo "<th>ID</th>";
        echo "<th>Título</th>";
        echo "<th>Status</th>";
        echo "<th>Created At</th>";
        echo "<th>Updated At</th>";
        echo "</tr>";
        
        foreach ($rotas as $rota) {
            echo "<tr>";
            echo "<td>{$rota['id']}</td>";
            echo "<td>{$rota['titulo']}</td>";
            echo "<td>{$rota['status']}</td>";
            echo "<td>{$rota['created_at']}</td>";
            echo "<td>{$rota['updated_at']}</td>";
            echo "</tr>";
        }
        echo "</table>";
    } else {
        echo "<p>Nenhuma rota encontrada.</p>";
    }
    
} catch (Exception $e) {
    echo "❌ Erro: " . $e->getMessage() . "<br>";
}
?>
