#include "..\script_component.hpp"

/*
 * Function: forge_client_org_fnc_acceptInvite
 * Author: J. Schmidt
 * 
 * Description:
 * Allows a player to accept an organization invite from their stored invites
 *
 * Arguments:
 * 0: _playerUID - Player UID <STRING>
 * 1: _playerName - Player Name <STRING>
 * 2: _inviteKey - Invite key from the player's invites <STRING>
 *
 * Return Value:
 * Success <BOOL>
 */

params [["_playerUID", "", [""]], ["_playerName", "", [""]], ["_inviteKey", "", [""]]];

if (_playerUID == "" || _playerName == "" || _inviteKey == "") exitWith { TRACE_3("Invalid parameters for accepting invitation",_playerUID,_playerName,_inviteKey); false };

private _playerInvites = GETVAR(profileNamespace,FORGE_ORG_INVITES,createHashMap);
private _invite = _playerInvites get _inviteKey;

if (isNil "_invite") exitWith { TRACE_1("Invite not found",_inviteKey); false };

private _orgName = _invite get "orgName";
private _ownerUID = _invite get "ownerUID";

[_ownerUID, _orgName, _playerUID, _playerName, "member"] call FUNC(join);