<?php
/**
 * debug_all_game.php
 * ⚠️ শুধু Debug-এর জন্য — all_game.json-এর আসল Structure,
 * আর তাতে ঠিক কী Field ব্যবহার হচ্ছে (Duplicate কেন ধরা
 * পড়ছে না) তা দেখানোর জন্য।
 */
header('Content-Type: text/plain; charset=utf-8');

$filePath = __DIR__ . '/deepanshu/api/webapi/data/all_game.json';

echo "File Path: $filePath\n";
echo "File Exists: " . (file_exists($filePath) ? "হ্যাঁ" : "না") . "\n";

if (file_exists($filePath)) {
    echo "File Size: " . filesize($filePath) . " bytes\n\n";

    $rawContent = file_get_contents($filePath);
    $jsonData = json_decode($rawContent, true);
    echo "JSON Decode Error: " . json_last_error_msg() . "\n\n";

    if ($jsonData !== null) {
        echo "Top-Level Key-গুলো: " . implode(', ', array_keys($jsonData)) . "\n\n";

        // ✅ Games-Array খুঁজে বের করা (Common Structure-গুলো Try করা)
        $games = $jsonData['data']['gameLists'] ?? $jsonData['gameLists'] ?? $jsonData ?? [];

        if (is_array($games)) {
            echo "মোট Game (Raw, Duplicate-সহ): " . count($games) . "\n\n";

            echo "প্রথম ৩টা Game-এর সম্পূর্ণ Structure:\n";
            for ($i = 0; $i < min(3, count($games)); $i++) {
                echo json_encode($games[$i], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n";
            }

            // ✅ gameCode/gameID দিয়ে, কতগুলো Unique তা Check করা
            $byGameCode = [];
            $byGameID = [];
            foreach ($games as $g) {
                if (isset($g['gameCode'])) $byGameCode[$g['gameCode']] = true;
                if (isset($g['gameID'])) $byGameID[$g['gameID']] = true;
            }
            echo "gameCode দিয়ে Unique-Count: " . count($byGameCode) . "\n";
            echo "gameID দিয়ে Unique-Count: " . count($byGameID) . "\n";
        }
    }
}
