#include "..\script_component.hpp"

/*
 * Author: IDSolutions
 * Saves arsenal/garage unlocks to appropriate storage based on persistence mode
 *
 * Arguments:
 * 0: Type <STRING> ("armory" or "garage")
 *
 * Return Value:
 * None
 *
 * Examples:
 * ["armory"] call forge_client_arsenal_fnc_saveUnlocks
 *
 * Public: Yes
 */

params [["_type", "", [""]]];

switch (_type) do {
    case "armory": {
        private _armory_data = GETVAR(player,Armory_Unlocks,GVAR(default_armory));
        
        switch (GVAR(pdb_mode)) do {
            case 0: {
                SETVAR(profileNamespace,Armory_Unlocks,_armory_data);
            };
            case 1: {
                ["hsetid", getPlayerUID player, "armory_unlocks", -1, _armory_data, "", false] remoteExec ["dragonfly_db_fnc_addTask", 2, false];
            };
            default {
                SETVAR(profileNamespace,Armory_Unlocks,_armory_data);
            };
        };

        [_type, _armory_data] call FUNC(updateUnlocks);
    };
    
    case "garage": {
        private _garage_data = GETVAR(player,Garage_Unlocks,GVAR(default_garage));
        
        switch (GVAR(pdb_mode)) do {
            case 0: {
                SETVAR(profileNamespace,Garage_Unlocks,_garage_data);
            };
            case 1: {
                ["hsetid", getPlayerUID player, "garage_unlocks", -1, _garage_data, "", false] remoteExec ["dragonfly_db_fnc_addTask", 2, false];
            };
            default {
                SETVAR(profileNamespace,Garage_Unlocks,_garage_data);
            };
        };

        [_type, _garage_data] call FUNC(updateUnlocks);
    };
};