#include "..\script_component.hpp"

{
    private _configName = configName(_x);
    private _className = (missionConfigFile >> "CfgStores" >> "stores" >> _configName >> "className") call BFUNC(getCfgData);
    private _pos = (missionConfigFile >> "CfgStores" >> "stores" >> _configName >> "pos") call BFUNC(getCfgData);
    private _dir = (missionConfigFile >> "CfgStores" >> "stores" >> _configName >> "dir") call BFUNC(getCfgData);
    private _type = (missionConfigFile >> "CfgStores" >> "stores" >> _configName >> "type") call BFUNC(getCfgData);
    private _name = (missionConfigFile >> "CfgStores" >> "stores" >> _configName >> "name") call BFUNC(getCfgData);
    private _categories = (missionConfigFile >> "CfgStores" >> "stores" >> _configName >> "categories") call BFUNC(getCfgData);
    private _paymentMethods = (missionConfigFile >> "CfgStores" >> "stores" >> _configName >> "paymentMethods") call BFUNC(getCfgData);
    private _products = (missionConfigFile >> "CfgStores" >> "stores" >> _configName >> "products") call BFUNC(getCfgData);

    if (_type == "object") then {
        private _store = createSimpleObject [_className, [0, 0, 0]];

        _store setPosATL _pos;
        _store setDir _dir;
        _store allowDamage false;
        _store setVariable ["storeData", [_categories, _products, _name, _paymentMethods], true];
        _store setVariable ["isStore", true, true];
    } else {
        private _group = createGroup civilian;
        private _store = _group createUnit [_className, [0, 0, 0], [], 0, "NONE"];

        _store disableAI "MOVE";
        _store setPosATL _pos;
        _store setDir _dir;
        _store allowDamage false;
        _store setVariable ["storeData", [_categories, _products, _name, _paymentMethods], true];
        _store setVariable ["isStore", true, true];
        _store setVariable ["BIS_enableRandomization", false];
    };

    diag_log text format ["[FORGE Store] ClassName: '%1' Pos: '%2' Dir: '%3' Type: '%4' Name: '%5'", _className, _pos, _dir, _type, _name];

} forEach ("true" configClasses (missionConfigFile >> "CfgStores" >> "stores"));