#include "..\script_component.hpp"

/*
 * Function: dragonfly_db_fnc_pubSubHandler
 * Author: Creedcoder, J.Schmidt
 * Edit: 07.15.2024
 * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved
 *
 * Do not edit without permission!
 *
 * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
 * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons,
 * PO Box 1866, Mountain View, CA 94042
 *
 * [Description]
 * Handles pub/sub messages and routes them through the CBA event system based on event type.
 *
 * Arguments:
 * 0: UniqueID for message tracking <STRING> (default: "")
 * 1: Event type (global, local, server, remote) <STRING> (default: "")
 * 2: Event name for CBA event system <STRING> (default: "")
 * 3: Message data [<ARRAY|STRING|NUMBER|BOOL>] (default: [])
 * 4: Target NetID for remote events <STRING> (default: "")
 *
 * Return Value:
 * None
 *
 * Examples:
 * ["123", "global", "myEvent", ["Hello"], ""] call dragonfly_db_fnc_pubSubHandler
 * ["456", "remote", "playerEvent", ["Update"], "2:3"] call dragonfly_db_fnc_pubSubHandler
 *
 * Public: Yes
 */

params [["_uniqueID", "", [""]], ["_eventType", "", [""]], ["_eventName", "", [""]], ["_data", [], [[]]], ["_target", "", [""]]];

switch (_eventType) do {
    case "global": {
        [_eventName, _data] call CFUNC(globalEvent);
    };
    case "local": {
        [_eventName, _data] call CFUNC(localEvent);
    };
    case "server": {
        [_eventName, _data] call CFUNC(serverEvent);
    };
    case "remote": {
        private _targetObj = objectFromNetId _target;
        [_eventName, _data, _targetObj] call CFUNC(remoteEvent);
    };
};