<?php
/**
 * Check all SMS settings for bank transaction notifications
 */
require_once 'config/database.php';

echo "<h2>Bank Transaction SMS Settings Check</h2>\n";

try {
    // Check if non-musking SMS service is enabled
    $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'non_musking_enabled'");
    $stmt->execute();
    $result = $stmt->fetch();
    $nonMuskingEnabled = $result && $result['setting_value'] === '1';
    
    echo "<p><strong>Non-musking SMS Service Enabled:</strong> " . ($nonMuskingEnabled ? '✅ YES' : '❌ NO') . "</p>\n";
    if ($result) {
        echo "<p>Value: " . htmlspecialchars($result['setting_value']) . "</p>\n";
    }
    
    // Check if bank transaction notifications are enabled
    $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'sms_send_bank_transaction_notifications'");
    $stmt->execute();
    $result = $stmt->fetch();
    $bankNotificationsEnabled = $result && $result['setting_value'] === '1';
    
    echo "<p><strong>Bank Transaction Notifications Enabled:</strong> " . ($bankNotificationsEnabled ? '✅ YES' : '❌ NO') . "</p>\n";
    if ($result) {
        echo "<p>Value: " . htmlspecialchars($result['setting_value']) . "</p>\n";
    }
    
    // Check MRAM API settings
    echo "<h3>MRAM API Configuration:</h3>\n";
    
    $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'non_musking_api_key'");
    $stmt->execute();
    $result = $stmt->fetch();
    echo "<p><strong>API Key:</strong> " . ($result && !empty($result['setting_value']) ? '✅ SET' : '❌ NOT SET') . "</p>\n";
    
    $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'non_musking_api_url'");
    $stmt->execute();
    $result = $stmt->fetch();
    echo "<p><strong>API URL:</strong> " . ($result ? htmlspecialchars($result['setting_value']) : 'NOT SET') . "</p>\n";
    
    $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'non_musking_sender_id'");
    $stmt->execute();
    $result = $stmt->fetch();
    echo "<p><strong>Sender ID:</strong> " . ($result ? htmlspecialchars($result['setting_value']) : 'NOT SET') . "</p>\n";
    
    // Check SMS templates
    echo "<h3>SMS Templates:</h3>\n";
    
    $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'non_musking_tpl_bank_transaction'");
    $stmt->execute();
    $result = $stmt->fetch();
    echo "<p><strong>Bank Transaction Template:</strong> " . ($result ? '✅ SET' : '❌ NOT SET') . "</p>\n";
    if ($result) {
        echo "<p>Template: " . htmlspecialchars($result['setting_value']) . "</p>\n";
    }
    
    $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'non_musking_tpl_bank_transaction_rejection'");
    $stmt->execute();
    $result = $stmt->fetch();
    echo "<p><strong>Bank Transaction Rejection Template:</strong> " . ($result ? '✅ SET' : '❌ NOT SET') . "</p>\n";
    if ($result) {
        echo "<p>Template: " . htmlspecialchars($result['setting_value']) . "</p>\n";
    }
    
    // Overall status
    echo "<h3>Status Summary:</h3>\n";
    if ($nonMuskingEnabled && $bankNotificationsEnabled) {
        echo "<p style='color: green; font-weight: bold;'>✅ ALL SETTINGS ARE CONFIGURED CORRECTLY</p>\n";
        echo "<p>SMS notifications should be working for bank transaction verification.</p>\n";
    } else {
        echo "<p style='color: red; font-weight: bold;'>❌ MISSING CONFIGURATION</p>\n";
        if (!$nonMuskingEnabled) {
            echo "<p>- Non-musking SMS service is disabled</p>\n";
        }
        if (!$bankNotificationsEnabled) {
            echo "<p>- Bank transaction notifications are disabled</p>\n";
        }
        echo "<p>Please enable these settings in the admin panel.</p>\n";
    }
    
} catch (PDOException $e) {
    echo "<p>Error connecting to database: " . htmlspecialchars($e->getMessage()) . "</p>\n";
}
?>