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

// Direct query to see all settings
$stmt = $pdo->prepare("SELECT * FROM settings WHERE setting_key LIKE '%musking%' ORDER BY setting_key");
$stmt->execute();
$results = $stmt->fetchAll();

echo "All musking-related settings:\n";
echo str_repeat("-", 50) . "\n";
foreach ($results as $row) {
    echo "Key: " . $row['setting_key'] . "\n";
    echo "Value: " . $row['setting_value'] . "\n";
    echo "Created: " . $row['created_at'] . "\n";
    echo "Updated: " . $row['updated_at'] . "\n";
    echo str_repeat("-", 30) . "\n";
}

// Try to insert the template again with more debugging
echo "\nTrying to insert fee payment template...\n";

$feePaymentTemplate = 'প্রিয় {name}, আপনার ফি {paid_amount} টাকা গৃহীত হয়েছে। বর্তমান বকেয়া: {due_amount} টাকা। ধন্যবাদ।';

try {
    // First delete if exists to avoid duplicate key issues
    $stmt = $pdo->prepare("DELETE FROM settings WHERE setting_key = ?");
    $stmt->execute(['non_musking_tpl_fee_payment']);
    
    // Then insert fresh
    $stmt = $pdo->prepare("INSERT INTO settings (setting_key, setting_value) VALUES (?, ?)");
    $result = $stmt->execute(['non_musking_tpl_fee_payment', $feePaymentTemplate]);
    
    if ($result) {
        echo "✅ Insert successful\n";
    } else {
        echo "❌ Insert failed\n";
    }
} catch (Exception $e) {
    echo "❌ Exception: " . $e->getMessage() . "\n";
}

// Check again
echo "\nChecking again after insert:\n";
$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 NOW found: " . $template['setting_value'] . "\n";
} else {
    echo "❌ Fee payment template STILL not found\n";
}
?>