<?php

class AuraGaming {

    function info($agent_code, $agent_token) {
        $postArray = [
            'method' => 'money_info', 
            'agent_code' => $agent_code, 
            'agent_token' => $agent_token,
            'all_users' => true
        ];
        return $this->send_request($postArray);
    }
    
    function balance($agent_code, $agent_token, $user_code) {
        $postArray = [
            'method' => 'money_info', 
            'agent_code' => $agent_code, 
            'agent_token' => $agent_token,
            'user_code' => $user_code
        ];
        return $this->send_request($postArray);
    }

    function create($agent_code, $agent_token, $user_code) {
        $postArray = [
            'method' => 'user_create', 
            'agent_code' => $agent_code, 
            'agent_token' => $agent_token,
            'user_code' => $user_code
        ];
        return $this->send_request($postArray);
    }

    function deposit($agent_code, $agent_token, $user_code, $amount) {
        $postArray = [
            'method' => 'user_deposit', 
            'agent_code' => $agent_code, 
            'agent_token' => $agent_token,
            'user_code' => $user_code,
            'amount' => $amount
        ];
        return $this->send_request($postArray);
    }

    function withdraw($agent_code, $agent_token, $user_code, $amount) {
        $postArray = [
            'method' => 'user_withdraw', 
            'agent_code' => $agent_code, 
            'agent_token' => $agent_token,
            'user_code' => $user_code,
            'amount' => $amount
        ];
        return $this->send_request($postArray);
    }

    function launch($agent_code, $agent_token, $user_code, $provider_code, $game_code, $lang) {
        $postArray = [
            'method' => 'game_launch',
            'agent_code' => $agent_code, 
            'agent_token' => $agent_token,
            'user_code' => $user_code,
            'provider_code' => $provider_code,
            'game_code' => $game_code,
            'lang' => $lang
        ];
        return $this->send_request($postArray);
    }

    function provider($agent_code, $agent_token) {
        $postArray = [
            'method' => 'provider_list', 
            'agent_code' => $agent_code, 
            'agent_token' => $agent_token
        ];
        return $this->send_request($postArray);
    }

    function gamelist($agent_code, $agent_token, $provider_code) {
        $postArray = [
            'method' => 'game_list', 
            'agent_code' => $agent_code, 
            'agent_token' => $agent_token,
            'provider_code' => $provider_code
        ];
        return $this->send_request($postArray);
    }

    function call_players($agent_code, $agent_token) {
        $postArray = [
            'method' => 'call_players', 
            'agent_code' => $agent_code, 
            'agent_token' => $agent_token
        ];
        return $this->send_request($postArray);
    }

    function call_list($agent_code, $agent_token, $provider_code, $game_code) {
        $postArray = [
            'method' => 'call_list', 
            'agent_code' => $agent_code, 
            'agent_token' => $agent_token,
            'provider_code' => $provider_code,
            'game_code' => $game_code
        ];
        return $this->send_request($postArray);
    }

    function call_apply($agent_code, $agent_token, $provider_code, $game_code, $user_code, $call_rtp, $call_type) {
        $postArray = [
            'method' => 'call_apply', 
            'agent_code' => $agent_code, 
            'agent_token' => $agent_token,
            'provider_code' => $provider_code,
            'game_code' => $game_code,
            'user_code' => $user_code,
            'call_rtp' => $call_rtp,
            'call_type' => $call_type
        ];
        return $this->send_request($postArray);
    }

    function call_rtp($agent_code, $agent_token, $provider_code, $user_code, $rtp) {
        $postArray = [
            'method' => 'call_rtp', 
            'agent_code' => $agent_code, 
            'agent_token' => $agent_token,
            'provider_code' => $provider_code,
            'user_code' => $user_code,
            'rtp' => $rtp
        ];
        return $this->send_request($postArray);
    }

    function send_request($postArray) {
        $jsonData = json_encode($postArray);
        $headerArray = ['Content-Type: application/json'];
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://api.nexusggr.com/'); // Update with the correct endpoint
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return response as string
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);

        $res = curl_exec($ch);
        if (curl_errno($ch)) {
            $error_msg = curl_error($ch);
            curl_close($ch);
            return $error_msg;
        }
        curl_close($ch);
        
        return $res;
    }
} 

$AG = new AuraGaming();

$agent_code = "XSan";
$agent_token = "1c66552cbd50665e57dfa8e00031d3df";

?>