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

echo "<h2>Updating MRAM SMS Configuration</h2>";

try {
    $stmt = $pdo->prepare("INSERT INTO settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = ?");
    
    // Update to the correct API URL from project memory
    $stmt->execute(['non_musking_api_url', 'https://sms.mram.com.bd/api/v3/send', 'https://sms.mram.com.bd/api/v3/send']);
    
    // Ensure username and password are set correctly
    $stmt->execute(['non_musking_username', 'C3002791', 'C3002791']);
    $stmt->execute(['non_musking_password', 'hPOWSnw8rf', 'hPOWSnw8rf']);
    
    // Clear API key since we're using Basic Auth
    $stmt->execute(['non_musking_api_key', '', '']);
    
    echo "✅ Configuration updated successfully!<br>";
    echo "<br><strong>New Configuration:</strong><br>";
    echo "• API URL: https://sms.mram.com.bd/api/v3/send ✓<br>";
    echo "• Authentication: HTTP Basic Auth ✓<br>";
    echo "• Username: C3002791 ✓<br>";
    echo "• Password: hPOWSnw8rf ✓<br>";
    echo "• Sender ID: SCHOOL ✓<br>";
    echo "• Payload Format: MRAM v3 format ✓<br>";
    
    echo "<br><h3>Changes Made:</h3>";
    echo "1. Updated API URL to correct MRAM v3 endpoint<br>";
    echo "2. Set proper Basic Authentication with your credentials<br>";
    echo "3. Updated payload format to match MRAM v3 requirements<br>";
    echo "4. Removed API Key authentication (not needed)<br>";
    
    echo "<br><strong>Next Steps:</strong><br>";
    echo "1. <a href='admin/test_non_musking_settings.php'>Test the configuration</a><br>";
    echo "2. Try sending a test SMS to verify it works<br>";
    echo "3. The system should now properly send SMS messages<br>";
    
} catch (Exception $e) {
    echo "<strong>❌ Error:</strong> " . $e->getMessage() . "<br>";
}
?>