#include "..\script_component.hpp"

/*
 * Function: forge_client_db_fnc_saveToProfile
 * Author: J.Schmidt
 * Edit: 07.23.2024
 * Copyright © 2024 J.Schmidt, All rights reserved
 *
 * Do not edit without permission!
 *
 * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivative 4.0 International License.
 * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to Creative Commons,
 * PO Box 1866, Mountain View, CA 94042
 *
 * [Description]
 * Store player data in Profile Namespace.
 *
 * Arguments:
 * N/A
 *
 * Return Value:
 * N/A
 *
 * Examples:
 * [] call forge_client_db_fnc_saveToProfile;
 *
 * Public: Yes
 */

// if (isNil "forge_client_armory_arsenalUnlocks") then { forge_client_armory_arsenalUnlocks = [] };
// if (isNil "forge_client_armory_garageUnlocks") then { forge_client_armory_garageUnlocks = [] };
if (isNil EGVAR(arsenal,armory_unlocks)) then { EGVAR(arsenal,armory_unlocks) = [[],[],[],[]] };
if (isNil EGVAR(arsenal,garage_unlocks)) then { EGVAR(arsenal,garage_unlocks) = [[],[],[],[],[],[]] };

private _data = [
["key", getPlayerUID player],
["armory_unlocks", [EGVAR(arsenal,armory_unlocks)]],
["garage_unlocks", [EGVAR(arsenal,garage_unlocks)]],
// ["locker", [player getVariable ["Locker", []]]],
// ["garage", [player getVariable ["Garage", []]]],
["locker", [GETVAR(player,FORGE_Locker,[])]],
["garage", [GETVAR(player,FORGE_Garage,[])]],
// ["cash", [player getVariable ["FORGE_Cash", 0]]],
// ["bank", [player getVariable ["FORGE_Bank", 0]]],
["cash", [GETVAR(player,FORGE_Cash,0)]],
["bank", [GETVAR(player,FORGE_Bank,0)]],
// ["number", [player getVariable ["FORGE_Phone_Number", "unknown"]]],
// ["email", [player getVariable ["FORGE_Email", "unknown@spearnet.mil"]]],
["number", [GETVAR(player,FORGE_PhoneNumber,"unknown")]],
["email", [GETVAR(player,FORGE_Email,"unknown@spearnet.mil")]],
// ["paygrade", [player getVariable ["Paygrade", "E1"]]],
["paygrade", [GETVAR(player,FORGE_Paygrade,"E1")]],
["reputation", [rating player]],
["loadout", [getUnitLoadout player]],
// ["holster", [player getVariable ["FORGE_Holster_Weapon", true]]],
["holster", [GETVAR(player,FORGE_Holster_Weapon,true)]],
["position", [getPosASLVisual player]],
["direction", [getDirVisual player]]
];

if (isNull objectParent player) then {
    _data pushBack ["currentWeapon", [currentMuzzle player]];
    _data pushBack ["stance", [stance player]];
};

private _hashMap = createHashMapFromArray _data;

// profileNamespace setVariable ["FORGE_PlayerData", _hashMap];
SETVAR(profileNamespace,FORGE_PlayerData,_hashMap);