<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

require 'koneksi.php';

echo "<pre>";

try {
    // INIT CLASS
    echo "✅ SGX class initialized\n\n";

    /* ===============================
       TEST 1: AGENT BALANCE
    =============================== */
    $agent = $SGX->agentbalance();
    echo "AGENT BALANCE:\n";
    print_r($agent);
    echo "\n";

    /* ===============================
       TEST USER
    =============================== */
    $username = 'TESTSGX123'; // ganti user test

    /* CREATE USER */
    $create = $SGX->create($username);
    echo "CREATE USER:\n";
    print_r($create);
    echo "\n";

    /* USER BALANCE */
    $balance = $SGX->userbalance($username);
    echo "USER BALANCE:\n";
    print_r($balance);
    echo "\n";

    /* DEPOSIT */
    $deposit = $SGX->deposit($username, 1000);
    echo "DEPOSIT 1000:\n";
    print_r($deposit);
    echo "\n";

    /* BALANCE AFTER DEPOSIT */
    $balance2 = $SGX->userbalance($username);
    echo "BALANCE AFTER DEPOSIT:\n";
    print_r($balance2);
    echo "\n";

    /* WITHDRAW */
    $withdraw = $SGX->withdraw($username, 500);
    echo "WITHDRAW 500:\n";
    print_r($withdraw);
    echo "\n";

    /* RESET BALANCE */
    $reset = $SGX->resetBalance($username);
    echo "RESET BALANCE:\n";
    print_r($reset);
    echo "\n";

    /* ===============================
       GAME TEST
    =============================== */
    $provider = 'RK'; // contoh provider
    $games = $SGX->gamelist($provider);
    echo "GAME LIST ($provider):\n";
    print_r($games);
    echo "\n";

    if (!empty($games['data']['games'][0]['game_code'])) {
        $gameCode = $games['data']['games'][0]['game_code'];

        $launch = $SGX->opengame($username, $gameCode);
        echo "OPEN GAME:\n";
        print_r($launch);
    }

} catch (Exception $e) {
    echo "❌ ERROR: ".$e->getMessage();
}

echo "</pre>";
