<?php
require_once __DIR__ . '/config/database.php';
require_once __DIR__ . '/includes/sms_helper.php';

echo "=== Non-Musking Configuration Test ===\n\n";

// Test configuration loading
$cfg = non_musking_config();
echo "Configuration loaded:\n";
print_r($cfg);

echo "\n=== Template Test ===\n";
$tpl = $cfg['templates']['fee_payment'] ?? 'NOT FOUND';
echo "Fee payment template: " . $tpl . "\n";

echo "\n=== API Key Test ===\n";
$api_key = $cfg['api_key'] ?? 'NOT SET';
echo "API Key: " . ($api_key ? 'SET' : 'NOT SET') . "\n";

if ($api_key) {
    echo "API Key value: " . substr($api_key, 0, 10) . "...\n";
}

echo "\n=== Enabled Test ===\n";
$enabled = $cfg['enabled'] ?? false;
echo "Enabled: " . ($enabled ? 'YES' : 'NO') . "\n";

echo "\n=== Template Interpolation Test ===\n";
if ($tpl !== 'NOT FOUND') {
    $vars = [
        'name' => 'Test Student',
        'paid_amount' => '500.00',
        'due_amount' => '0.00'
    ];
    $message = sms_interpolate($tpl, $vars);
    echo "Interpolated message: " . $message . "\n";
} else {
    echo "Cannot test interpolation - template not found\n";
}

echo "\n=== Final Status ===\n";
if ($enabled && $tpl !== 'NOT FOUND' && $api_key) {
    echo "✅ All requirements met for sending SMS\n";
} else {
    echo "❌ Missing requirements:\n";
    if (!$enabled) echo "  - Non-musking not enabled\n";
    if ($tpl === 'NOT FOUND') echo "  - Fee payment template missing\n";
    if (!$api_key) echo "  - API key not set\n";
}
?>