package _VisualDVM.ServerObjectsCache;
import _VisualDVM.Global;
import _VisualDVM.ProjectData.LanguageName;
import _VisualDVM.TestingSystem.Common.Group.Group;
import _VisualDVM.TestingSystem.SAPFOR.SapforConfiguration.SapforConfiguration;
import _VisualDVM.TestingSystem.SAPFOR.SapforConfigurationGroup.SapforConfigurationGroup;
import _VisualDVM.TestingSystem.SAPFOR.SapforConfigurationSettings.SapforConfigurationSettings;
import _VisualDVM.TestingSystem.SAPFOR.SapforSettings.SapforSettings;

import java.util.LinkedHashMap;
import java.util.Vector;
public class SapforConfigurationCache extends ConfigurationCache {
    public SapforConfigurationCache(SapforConfiguration configuration) {
        super(configuration);
        groupsSummary = new Vector<>();
        Vector<SapforConfigurationGroup> configurationGroups = Global.testingServer.db.getVectorByFK(configuration, SapforConfigurationGroup.class);
        //--
        LinkedHashMap<LanguageName, Vector<String>> gmap = new LinkedHashMap<>();
        for (SapforConfigurationGroup configurationGroup : configurationGroups) {
            if (Global.testingServer.db.groups.containsKey(configurationGroup.group_id)) {
                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<SapforConfigurationSettings> configurationSettings = Global.testingServer.db.getVectorByFK(configuration, SapforConfigurationSettings.class);
        Vector<String> settingsDescriptionsVector = new Vector<>();
        for (SapforConfigurationSettings settings : configurationSettings) {
            SapforSettings dvmSettings = Global.testingServer.db.sapforSettings.get(settings.sapforsettings_id);
            settingsDescriptionsVector.add(dvmSettings.description);
        }
        settingsSummary = String.join(";", settingsDescriptionsVector);
        //-
        testsCount = Global.testingServer.db.getSapforConfigurationTestsIds(configuration).size();
    }
}
