<?php
/**
 * check_json_files.php
 * সব Vendor-JSON File Check করে, কোনটায় Game আছে,
 * কোনটা খালি/Missing — তার একটা Report দেয়।
 * ⚠️ এটা শুধু Diagnostic/Check-এর জন্য — Test করার পর
 * Server থেকে মুছে ফেলতে পারো (Security-এর জন্য ভালো)।
 */
header('Content-Type: text/html; charset=utf-8');

$vendorMap = [
    'CQ9' => 'cq9.json', 'JDB' => 'jdb.json', 'JILI' => 'jili.json',
    'PG' => 'pgsoft.json', 'KM' => 'km.json', 'EG' => 'eg.json',
    'IDG' => 'idg.json', 'V8' => 'v8.json', 'MG' => 'mg.json',
    'MG_FISH' => 'mg_fish.json', 'EVOLIVE' => 'evolive.json',
    'EVO' => 'evo.json', 'G9' => 'g9.json', '5G' => '5g.json',
    '2J' => '2j.json', 'BNG' => 'bng.json', 'BTG' => 'btg.json',
    '100HP' => '100hp.json', 'EAZYGAME' => 'eazygame.json',
    'FASTSPIN' => 'fastspin.json', 'INOUT' => 'inout.json',
    'CARD365' => 'card365.json', 'PP' => 'pp.json',
    'PRAGMATIC' => 'PRAGMATIC.json',
];

echo "<!DOCTYPE html><html><head><meta charset='UTF-8'><title>JSON File Check</title>";
echo "<style>body{background:#0a0a0a;color:#fff;font-family:sans-serif;padding:20px;}
table{width:100%;border-collapse:collapse;} td,th{padding:10px;border-bottom:1px solid #333;text-align:left;font-size:13px;}
.ok{color:#22D67A;font-weight:700;} .bad{color:#FF5C7A;font-weight:700;} .empty{color:#FFC107;font-weight:700;}</style></head><body>";
echo "<h2>📊 Vendor-JSON File Check</h2><table>";
echo "<tr><th>Vendor</th><th>File</th><th>অবস্থা</th><th>Game-সংখ্যা</th></tr>";

foreach ($vendorMap as $vendor => $file) {
    $path = __DIR__ . '/deepanshu/api/webapi/data/' . $file;
    echo "<tr><td>$vendor</td><td>$file</td>";

    if (!file_exists($path)) {
        echo "<td class='bad'>❌ File পাওয়া যায়নি</td><td>-</td>";
    } else {
        $content = json_decode(file_get_contents($path), true);
        $games = $content['gameLists'] ?? $content ?? [];
        $count = is_array($games) ? count($games) : 0;

        if ($count === 0) {
            echo "<td class='empty'>⚠️ খালি (কোনো Game নেই)</td><td>0</td>";
        } else {
            echo "<td class='ok'>✅ ঠিক আছে</td><td>$count</td>";
        }
    }
    echo "</tr>";
}
echo "</table></body></html>";
