<?php
echo "<h2>MRAM Developers Portal API Key Verification</h2>";

// MRAM Developers Portal credentials as provided
$mram_credentials = [
    'username' => 'C3002791',
    'password' => 'hPOWSnw8rf',
    'api_key' => 'C30027916974e980709412.23354057',  // This is the key from MRAM portal
    'sender_id' => '8809601016579',
    'api_url' => 'https://rest.mrmessaging.net/messages'
];

echo "<h3>Official MRAM Developers Portal Credentials:</h3>";
echo "<p><strong>Portal URL:</strong> <a href='https://sms.mram.com.bd/Developers' target='_blank'>https://sms.mram.com.bd/Developers</a></p>";
echo "<ul>";
foreach ($mram_credentials as $key => $value) {
    if ($key === 'password') {
        echo "<li><strong>$key:</strong> ******** (hidden)</li>";
    } else {
        echo "<li><strong>$key:</strong> $value</li>";
    }
}
echo "</ul>";

echo "<h3>API Key Details:</h3>";
echo "<p><strong>API Key:</strong> {$mram_credentials['api_key']}</p>";
echo "<p><strong>Length:</strong> " . strlen($mram_credentials['api_key']) . "</p>";
echo "<p><strong>Format:</strong> CompanyCode + UniqueIdentifier</p>";
echo "<p><strong>Company Code:</strong> " . substr($mram_credentials['api_key'], 0, 8) . "</p>";
echo "<p><strong>Unique Part:</strong> " . substr($mram_credentials['api_key'], 8) . "</p>";

// Check for common issues
$issues = [];
if (strlen($mram_credentials['api_key']) !== 32) {
    $issues[] = "API key length is not 32 characters";
}
if (!preg_match('/^[A-Za-z0-9.]+$/', $mram_credentials['api_key'])) {
    $issues[] = "API key contains invalid characters";
}

if (empty($issues)) {
    echo "<p style='color:green; font-size:18px;'><strong>✅ API Key format is correct!</strong></p>";
} else {
    echo "<p style='color:red; font-size:18px;'><strong>⚠️ Issues found:</strong></p>";
    foreach ($issues as $issue) {
        echo "<p style='color:red;'>- $issue</p>";
    }
}

echo "<h3>Validation Instructions:</h3>";
echo "<ol>";
echo "<li>Log into <a href='https://sms.mram.com.bd/Developers' target='_blank'>https://sms.mram.com.bd/Developers</a></li>";
echo "<li>Navigate to API Credentials section</li>";
echo "<li>Verify the API key matches: {$mram_credentials['api_key']}</li>";
echo "<li>Ensure all credentials are exactly as shown above</li>";
echo "</ol>";

echo "<h3>Next Steps:</h3>";
echo "<ul>";
echo "<li>Compare with your local database settings</li>";
echo "<li>Update any mismatched credentials</li>";
echo "<li>Test SMS functionality after synchronization</li>";
echo "</ul>";
?>