<?php

// Connect to the database
require_once('pdo.php');
require_once('get_provider_translit.php');
require ('create_images.php');

$id = 6; 
$provider_translit = getProviderTranslit($id);

$curlCommand = 'curl -X GET "https://cms.nolimitcity.com/api/games?sort%5B0%5D=releaseDate%3Adesc&populate%5Breviews%5D%5Bpopulate%5D=%2A&populate%5Breviews%5D%5Breviewer%5D%5Bpopulate%5D=%2A&populate%5Bicon%5D=%2A&populate%5Bmath%5D=%2A&populate%5Binformation%5D=%2A&populate%5BxMechanics%5D%5Bpopulate%5D=%2A&populate%5Blogo%5D=%2A&pagination%5BpageSize%5D=999" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer 92cfd365f5e1c367c3ac4339791a97ee321b544d0fcf0a11efec763e59f064bcfa52f639b440b386d95101f1af9c025662ee606de32b52fdf4493f7fdece68d4ce88df71299adb260509e0c4e00ae4438628275f14e66b86abdcf0b93a7047e7a905b7096acad2e03f734ed97697f70706f6be653a7a2090c22ee17acecd9a79"';

$result = shell_exec($curlCommand);

if ($result === false) {
} else {
    $games = json_decode($result, true)['data'];
}

$insertedGames = [];

foreach ($games as $game) {

        $link = "";

        $name = $game['attributes']['name'];
        $name = str_replace("®", "", $name);
        $name = trim($name);

        $provider_id = $id;

        $translit = str_replace(" ", "-", $name);
        $translit = str_replace("&#039;", "-", $translit);
        $translit = str_replace("&#8211;", "-", $translit);
        $translit = str_replace("&#8217;", "-", $translit);
        $translit = preg_replace("/[^a-zA-Z0-9\-]/", "", $translit);
        $translit = str_replace("---", "-", $translit);
        $translit = str_replace("--", "-", $translit);

        $gameId = $game['attributes']['gameId'];
        
        $demo_desk = "https://www.nolimitcity.com/load-game/?game=".$gameId."&device=desktop";

        $demo_mob = "https://www.nolimitcity.com/load-game/?game=".$gameId."&device=mobile";

        $volatility = 0;

        $rtp = 0.0;

        $rtp_low = 0.0;

        $rtp_high = 0.0;

        $max_win = 0.0;

        $img = $game['attributes']['logo']['data']['attributes']['url'];

        createImage($provider_translit, $translit, $img); 

        require ('insert_values.php');

        require ('inserted_games.php');

}

// echo json_encode(['insertedGames' => $insertedGames]);
?>