<?php
require_once __DIR__ . '/../config/config_enhanced.php';
require_once __DIR__ . '/../classes/Database.php';

ini_set('display_errors', 1);
error_reporting(E_ALL);
try {
    $db = Database::getInstance();
    echo "Connected DB\n";
    $t = $db->fetch('SELECT id, name, template_name, status, created_at FROM message_templates WHERE template_name = ? ORDER BY created_at DESC LIMIT 1', ['auto_test_template_001']);
    if ($t) {
        echo "Found template: " . json_encode($t) . PHP_EOL;
    } else {
        echo "Not found\n";
        $rows = $db->fetchAll('SELECT id, name, template_name, status, created_at FROM message_templates ORDER BY created_at DESC LIMIT 10');
        echo "Recent: " . json_encode($rows) . PHP_EOL;
    }
} catch (Exception $e) {
    echo 'ERROR: ' . $e->getMessage() . PHP_EOL;
}
