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

echo "<h2>Checking MRAM Authentication Method</h2>";

// Get current configuration
$config = non_musking_config();

echo "<h3>Current Configuration:</h3>";
echo "<ul>";
echo "<li>Enabled: " . ($config['enabled'] ? 'Yes' : 'No') . "</li>";
echo "<li>API URL: " . htmlspecialchars($config['api_url'] ?? 'Not set') . "</li>";
echo "<li>Username: " . (!empty($config['username']) ? 'Set' : 'Not set') . "</li>";
echo "<li>Password: " . (!empty($config['password']) ? 'Set' : 'Not set') . "</li>";
echo "<li>API Key: " . (!empty($config['api_key']) ? 'Set' : 'Not set') . "</li>";
echo "<li>Sender ID: " . htmlspecialchars($config['sender_id'] ?? 'Not set') . "</li>";
echo "</ul>";

// Check which authentication method is being used
if (!empty($config['api_key'])) {
    echo "<p><strong>Using API Key Authentication (App)</strong></p>";
    echo "<p>API Key: " . substr($config['api_key'], 0, 10) . "...</p>";
} elseif (!empty($config['username']) && !empty($config['password'])) {
    echo "<p><strong>Using Basic Authentication</strong></p>";
    echo "<p>Username: " . $config['username'] . "</p>";
} else {
    echo "<p><strong>No valid authentication method configured</strong></p>";
}

// Test different authentication methods
echo "<h3>Testing Authentication Methods:</h3>";

// Test with API Key first
if (!empty($config['api_key'])) {
    echo "<p>Trying API Key authentication (App)...</p>";
    // This would be tested in the actual API call
} else {
    echo "<p>API Key not configured, will use Basic Auth</p>";
}

// Test with username/password
if (!empty($config['username']) && !empty($config['password'])) {
    echo "<p>Username/Password are configured for Basic Auth</p>";
} else {
    echo "<p>Username/Password not configured</p>";
}

echo "<h3>Recommended Actions:</h3>";
echo "<ol>";
echo "<li>Verify your MRAM account credentials are correct</li>";
echo "<li>Check if your account has API access enabled</li>";
echo "<li>Make sure the API Key is correctly copied: C30027916974e980709412.23354057</li>";
echo "<li>Ensure your account has sufficient balance</li>";
echo "<li>Contact MRAM support to verify API access is enabled for your account</li>";
echo "</ol>";

// Show sample API call structure
echo "<h3>Sample API Request Structure:</h3>";
echo "<pre>";
echo "POST https://rest.mrmessaging.net/messages\n";
echo "Headers:\n";
echo "  Content-Type: application/json\n";
echo "  Accept: application/json\n";
echo "  Authorization: App C30027916974e980709412.23354057\n";
echo "\n";
echo "Body:\n";
echo "  {\n";
echo "    \"mobile_number\": \"+8801712345678\",\n";
echo "    \"sms\": \"Test message\",\n";
echo "    \"sender_id\": \"8809601016579\"\n";
echo "  }\n";
echo "</pre>";

?>