<?php
require_once 'config/database.php';

// Set content type for web access
header('Content-Type: text/plain; charset=UTF-8');

echo "=== Sender ID Database Check ===\n\n";

try {
    // Check specifically for non_musking_sender_id
    $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'non_musking_sender_id'");
    $stmt->execute();
    $result = $stmt->fetch();
    
    if ($result) {
        echo "✅ Found non_musking_sender_id in database: " . $result['setting_value'] . "\n";
    } else {
        echo "❌ non_musking_sender_id NOT FOUND in database\n";
    }
    
    // Check all non_musking settings
    echo "\nAll non_musking settings:\n";
    echo "-------------------------\n";
    $stmt = $pdo->query("SELECT setting_key, setting_value FROM settings WHERE setting_key LIKE 'non_musking_%' ORDER BY setting_key");
    while($row = $stmt->fetch()) {
        echo $row['setting_key'] . ': ' . $row['setting_value'] . "\n";
    }
    
    // Test the configuration loading
    echo "\n=== Configuration Loading Test ===\n";
    require_once 'includes/sms_helper.php';
    $config = non_musking_config();
    
    echo "Loaded configuration:\n";
    echo "  Enabled: " . ($config['enabled'] ? 'Yes' : 'No') . "\n";
    echo "  Sender ID: " . ($config['sender_id'] ?? 'NOT SET') . "\n";
    echo "  API Key: " . (!empty($config['api_key']) ? 'SET' : 'NOT SET') . "\n";
    echo "  API URL: " . ($config['api_url'] ?? 'NOT SET') . "\n";
    
    // Test what would be used in the API call
    echo "\n=== API Construction Test ===\n";
    $sender_id = $config['sender_id'] ?? 'SCHOOL';
    echo "Sender ID that would be used: " . $sender_id . "\n";
    
    if ($sender_id === 'SCHOOL') {
        echo "⚠️  WARNING: Using default 'SCHOOL' sender ID instead of your configured 8809601016579\n";
        echo "This suggests the database setting is not properly stored or loaded.\n";
    } else {
        echo "✅ Using configured sender ID: " . $sender_id . "\n";
    }
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}

echo "\n=== End Check ===\n";
?>