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

try {
    // Insert the fee payment template
    $feePaymentTemplate = 'প্রিয় {name}, আপনার ফি {paid_amount} টাকা গৃহীত হয়েছে। বর্তমান বকেয়া: {due_amount} টাকা। ধন্যবাদ।';
    
    $stmt = $pdo->prepare("INSERT INTO settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value)");
    $result1 = $stmt->execute(['non_musking_tpl_fee_payment', $feePaymentTemplate]);
    
    // Enable non-musking SMS
    $result2 = $stmt->execute(['non_musking_enabled', '1']);
    
    if ($result1 && $result2) {
        echo "✅ Templates and settings updated successfully!\n";
        
        // Verify the template was added
        $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'non_musking_tpl_fee_payment'");
        $stmt->execute();
        $template = $stmt->fetch();
        
        if ($template) {
            echo "✅ Fee payment template: " . $template['setting_value'] . "\n";
        } else {
            echo "❌ Fee payment template not found\n";
        }
        
        // Verify non-musking is enabled
        $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'non_musking_enabled'");
        $stmt->execute();
        $enabled = $stmt->fetch();
        
        if ($enabled && $enabled['setting_value'] === '1') {
            echo "✅ Non-musking SMS is enabled\n";
        } else {
            echo "❌ Non-musking SMS is not enabled\n";
        }
    } else {
        echo "❌ Failed to update settings\n";
    }
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
?>