<?php
/**
 * Debug de plantillas - Ver qué plantillas hay y con qué códigos de idioma
 */

require_once 'config/config.php';

header('Content-Type: text/plain; charset=utf-8');

try {
    $db = Database::getInstance();
    
    echo "=== PLANTILLAS EN BASE DE DATOS ===\n\n";
    
    $stmt = $db->query("SELECT template_name, language_code, status FROM message_templates ORDER BY template_name, language_code");
    $templates = $stmt->fetchAll();
    
    if (empty($templates)) {
        echo "❌ No hay plantillas en la base de datos\n";
    } else {
        echo "📋 Plantillas encontradas:\n\n";
        foreach ($templates as $template) {
            echo "• Nombre: {$template['template_name']}\n";
            echo "  Idioma: {$template['language_code']}\n";
            echo "  Estado: {$template['status']}\n";
            echo "  -----\n";
        }
    }
    
    echo "\n=== CONFIGURACIÓN ACTUAL ===\n";
    $config = getWhatsAppConfigFromDB();
    echo "Token presente: " . (empty($config['token']) ? '❌ NO' : '✅ SÍ (' . strlen($config['token']) . ' chars)') . "\n";
    echo "Phone ID: " . ($config['phone_number_id'] ?? 'No configurado') . "\n";
    echo "API URL: " . ($config['api_url'] ?? 'No configurada') . "\n";
    
} catch (Exception $e) {
    echo "❌ Error: " . $e->getMessage() . "\n";
}
?>