<?php
header('Content-Type: text/plain');

//$url = 'https://api.casinoscores.com/svc-evolution-game-events/api/immersiveroulette?limit=50'; // fetch 1 latest spin
$url = 'https://api.casinoscores.com/svc-evolution-game-events/api/autoroulette?limit=50';
$response = file_get_contents($url);
$data = json_decode($response, true);

$result = [];

if (is_array($data)) {
    foreach ($data as $item) {
        if (isset($item['data']['result']['outcome']['number'])) {
            $result[] = [
                "data" => [
                    "settledAt" => $item['data']['settledAt'] ?? gmdate("Y-m-d\TH:i:s\Z"),
                    "result" => [
                        "outcome" => [
                            "number" => $item['data']['result']['outcome']['number']
                        ]
                    ]
                ]
            ];
        }
    }
}

echo json_encode($result);
