#include "..\script_component.hpp"

/*
 * Author: IDSolutions
 * Sends database requests to the server using CBA events
 *
 * Arguments:
 * 0: _type - Type of database operation <STRING>
 * 1: _data - Data for the operation <ANY>
 * 2: _callback - Function to call when data is returned <CODE>
 *
 * Return Value:
 * Request ID <STRING>
 *
 * Example:
 * ["hgetall", "Hello World!", { systemChat format ["Message: %1", _this]; }] call forge_db_fnc_requestServerDB;
 *
 * Public: Yes
 */

params [
    ["_type", "", [""]],
    ["_data", nil, [createHashMap, [], "", 0, true, objNull]],
    ["_callback", {}, [{}]]
];

private _requestID = format ["%1_%2", diag_tickTime, random 1000];

if (isNil QGVAR(pendingCallbacks)) then {
    GVAR(pendingCallbacks) = createHashMap;
};

GVAR(pendingCallbacks) set [_requestID, _callback];

["forge_db_request", [getPlayerUID player, _type, _data, _requestID]] call CBA_fnc_serverEvent;

_requestID