#include "..\script_component.hpp"

params ["_className", "_price", "_configType", "_itemType"];

private _displayName = "";
// private _locker = player getVariable ["FORGE_Locker", []];
private _locker = GETVAR(player,FORGE_Locker,[]);

if !([_price] call FUNC(handlePurchase)) exitWith {};

switch (_configType) do {
    case "item": {
        _displayName = getText (configFile >> "CfgWeapons" >> _className >> "displayName");
        _locker pushBack [_itemType, _className];
    };
    case "weapon": {
        _displayName = getText (configFile >> "CfgWeapons" >> _className >> "displayName");
        _locker pushBack [_itemType, _className];
    };
    case "magazine": {
        _displayName = getText (configFile >> "CfgMagazines" >> _className >> "displayName");
        _locker pushBack [_itemType, [_className, getNumber (configFile >> "CfgMagazines" >> _className >> "count"), getNumber (configFile >> "CfgMagazines" >> _className >> "count")]];
    };
    case "backpack": {
        _displayName = getText (configFile >> "CfgVehicles" >> _className >> "displayName");
        _locker pushBack [_itemType, _className];
    };
};

// player setVariable ["FORGE_Locker", _locker, true];
SETPVAR(player,FORGE_Locker,_locker);

[_className, _itemType] call EFUNC(arsenal,addArmoryItem);

[format ["You have purchased %1 for $%2.", _displayName, _price], "info", 3, "right"] call EFUNC(misc,notify);