/**
 * Author: dkanus
 * Home repo: https://www.insultplayers.ru/git/AcediaFramework/AcediaCore
 * License: GPL
 * Copyright 2023 Anton Tarasenko
 *------------------------------------------------------------------------------
 * This file is part of Acedia.
 *
 * Acedia is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License, or
 * (at your option) any later version.
 *
 * Acedia is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Acedia.  If not, see <https://www.gnu.org/licenses/>.
 */
class CommandPermissions extends AcediaConfig
    perobjectconfig
    config(AcediaCommands)
    abstract;

var public config array<string> forbiddenSubCommands;

protected function HashTable ToData() {
    local int i;
    local HashTable data;
    local ArrayList forbiddenList;

    data = _.collections.EmptyHashTable();
    forbiddenList = _.collections.EmptyArrayList();
    for (i = 0; i < forbiddenSubCommands.length; i += 1) {
        forbiddenList.AddString(Locs(forbiddenSubCommands[i]));
    }
    data.SetItem(P("forbiddenSubCommands"), forbiddenList);
    _.memory.Free(forbiddenList);
    return data;
}

protected function FromData(HashTable source) {
    local int i;
    local ArrayList forbiddenList;

    if (source == none)         return;
    forbiddenList = source.GetArrayList(P("forbiddenSubCommands"));
    if (forbiddenList == none)  return;

    forbiddenSubCommands.length = 0;
    for (i = 0; i < forbiddenList.GetLength(); i += 1) {
        forbiddenSubCommands[i] = forbiddenList.GetString(i);
    }
    _.memory.Free(forbiddenList);
}

protected function DefaultIt() {
    forbiddenSubCommands.length = 0;
}

defaultproperties {
    configName = "AcediaCommands"
    supportsDataConversion = true
}