<?php
require_once 'conexao.php';

echo "<h2>🔍 Verificando Estrutura da Tabela rota_clientes</h2>";

try {
    $pdo = conectarBanco();
    
    // Verificar estrutura da tabela
    $sqlStructure = "DESCRIBE rota_clientes";
    $stmtStructure = $pdo->query($sqlStructure);
    $structure = $stmtStructure->fetchAll(PDO::FETCH_ASSOC);
    
    echo "<h3>Estrutura da Tabela:</h3>";
    echo "<table border='1'>";
    echo "<tr><th>Campo</th><th>Tipo</th><th>Null</th><th>Key</th><th>Default</th><th>Extra</th></tr>";
    foreach ($structure as $field) {
        echo "<tr>";
        echo "<td>{$field['Field']}</td>";
        echo "<td>{$field['Type']}</td>";
        echo "<td>{$field['Null']}</td>";
        echo "<td>{$field['Key']}</td>";
        echo "<td>{$field['Default']}</td>";
        echo "<td>{$field['Extra']}</td>";
        echo "</tr>";
    }
    echo "</table>";
    
    // Verificar dados do cliente específico
    echo "<h3>Dados do Cliente ID 82:</h3>";
    $sqlCliente = "SELECT * FROM rota_clientes WHERE id = 82";
    $stmtCliente = $pdo->query($sqlCliente);
    $cliente = $stmtCliente->fetch(PDO::FETCH_ASSOC);
    
    if ($cliente) {
        echo "<table border='1'>";
        echo "<tr><th>Campo</th><th>Valor</th></tr>";
        foreach ($cliente as $campo => $valor) {
            echo "<tr>";
            echo "<td>$campo</td>";
            echo "<td>" . htmlspecialchars($valor) . "</td>";
            echo "</tr>";
        }
        echo "</table>";
    } else {
        echo "❌ Cliente ID 82 não encontrado";
    }
    
    // Verificar se há triggers ou constraints
    echo "<h3>Verificando Triggers:</h3>";
    $sqlTriggers = "SHOW TRIGGERS WHERE `Table` = 'rota_clientes'";
    $stmtTriggers = $pdo->query($sqlTriggers);
    $triggers = $stmtTriggers->fetchAll(PDO::FETCH_ASSOC);
    
    if (empty($triggers)) {
        echo "✅ Nenhum trigger encontrado na tabela rota_clientes";
    } else {
        echo "<table border='1'>";
        echo "<tr><th>Trigger</th><th>Event</th><th>Timing</th><th>Statement</th></tr>";
        foreach ($triggers as $trigger) {
            echo "<tr>";
            echo "<td>{$trigger['Trigger']}</td>";
            echo "<td>{$trigger['Event']}</td>";
            echo "<td>{$trigger['Timing']}</td>";
            echo "<td>{$trigger['Statement']}</td>";
            echo "</tr>";
        }
        echo "</table>";
    }
    
} catch (Exception $e) {
    echo "❌ Erro: " . $e->getMessage();
}
?> 
