package _VisualDVM.ServerObjectsCache;
import _VisualDVM.Global;
import _VisualDVM.ProjectData.LanguageName;
import _VisualDVM.TestingSystem.Common.Group.Group;
import _VisualDVM.TestingSystem.DVM.DVMConfiguration.DVMConfiguration;
import _VisualDVM.TestingSystem.DVM.DVMConfigurationGroup.DVMConfigurationGroup;
import _VisualDVM.TestingSystem.DVM.DVMConfigurationSettings.DVMConfigurationSettings;
import _VisualDVM.TestingSystem.DVM.DVMSettings.DVMSettings;

import java.util.LinkedHashMap;
import java.util.Vector;
public class DVMConfigurationCache extends ConfigurationCache {
    public DVMConfigurationCache(DVMConfiguration configuration) {
        super(configuration);
        groupsSummary = new Vector<>();
        Vector<DVMConfigurationGroup> configurationGroups = Global.testingServer.db.getVectorByFK(configuration, DVMConfigurationGroup.class);
        //--
        LinkedHashMap<LanguageName, Vector<String>> gmap = new LinkedHashMap<>();
        for (DVMConfigurationGroup configurationGroup : configurationGroups) {
            Group group = Global.testingServer.db.groups.get(configurationGroup.group_id);
            Vector<String> vector = null;
            if (gmap.containsKey(group.language)) {
                vector = gmap.get(group.language);
            } else {
                vector = new Vector<>();
                gmap.put(group.language, vector);
            }
            vector.add(group.description);
        }
        for (LanguageName language : gmap.keySet()) {
            groupsSummary.add(language + ": " + String.join(";", gmap.get(language)));
        }
        //--
        Vector<DVMConfigurationSettings> configurationSettings = Global.testingServer.db.getVectorByFK(configuration, DVMConfigurationSettings.class);
        Vector<String> settingsDescriptionsVector = new Vector<>();
        for (DVMConfigurationSettings settings : configurationSettings) {
            DVMSettings dvmSettings = Global.testingServer.db.dvmSettings.get(settings.dvmsettings_id);
            settingsDescriptionsVector.add(dvmSettings.description);
        }
        settingsSummary = String.join(";", settingsDescriptionsVector);
        //--
        testsCount = Global.testingServer.db.getDVMConfigurationTestsIds(configuration).size();
    }
}
