<?php
/**
 * Check current bank transaction SMS settings
 */

require_once 'config/database.php';

try {
    echo "Checking bank transaction SMS settings...\n\n";
    
    // Check non-musking 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'] : 'Not set';
    echo "non_musking_enabled: " . $nonMuskingEnabled . "\n";
    
    // Check bank transaction notifications 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'] : 'Not set';
    echo "sms_send_bank_transaction_notifications: " . $bankNotificationsEnabled . "\n";
    
    // Check bank transaction template
    $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'non_musking_tpl_bank_transaction'");
    $stmt->execute();
    $result = $stmt->fetch();
    $bankTemplate = $result ? $result['setting_value'] : 'Not set';
    echo "non_musking_tpl_bank_transaction: " . $bankTemplate . "\n";
    
    // Check bank transaction rejection template
    $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'non_musking_tpl_bank_transaction_rejection'");
    $stmt->execute();
    $result = $stmt->fetch();
    $bankRejectionTemplate = $result ? $result['setting_value'] : 'Not set';
    echo "non_musking_tpl_bank_transaction_rejection: " . $bankRejectionTemplate . "\n";
    
    echo "\n";
    if ($nonMuskingEnabled === '1' && $bankNotificationsEnabled === '1') {
        echo "✅ Both settings are enabled - SMS should work!\n";
    } else {
        echo "❌ SMS notifications are disabled. Please run setup_bank_sms_notifications.php\n";
    }
    
    // Check if the settings exist at all
    $stmt = $pdo->prepare("SELECT COUNT(*) FROM settings WHERE setting_key IN ('non_musking_enabled', 'sms_send_bank_transaction_notifications')");
    $stmt->execute();
    $count = $stmt->fetchColumn();
    echo "\nFound $count/2 required settings in database.\n";
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}