package SapforTestingSystem.Json;
import GlobalData.Tasks.TaskState;
import SapforTestingSystem.SapforTask.SapforTask;
import com.google.gson.annotations.Expose;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Vector;
public class SapforTasksResults_json {
    @Expose
    public long StartDate = 0;
    @Expose
    public long EndDate = 0;
    @Expose
    public List<SapforTask> tasks = new Vector<>();
    public LinkedHashMap<String, LinkedHashMap<String, Vector<SapforTask>>> sortTasksByConfigurationsAndGroups() {
        LinkedHashMap<String, LinkedHashMap<String, Vector<SapforTask>>> tasksByConfigurations = new LinkedHashMap<>();
        //--
        for (SapforTask task : tasks) {
            LinkedHashMap<String, Vector<SapforTask>> groups_tasks = null;
            if (tasksByConfigurations.containsKey(task.sapfor_configuration_id)) {
                groups_tasks = tasksByConfigurations.get(task.sapfor_configuration_id);
            } else {
                groups_tasks = new LinkedHashMap<>();
                tasksByConfigurations.put(task.sapfor_configuration_id, groups_tasks);
            }
            Vector<SapforTask> tasks = null;
            if (groups_tasks.containsKey(task.group_description)) {
                tasks = groups_tasks.get(task.group_description);
            } else {
                tasks = new Vector<>();
                groups_tasks.put(task.group_description, tasks);
            }
            tasks.add(task);
        }
        return tasksByConfigurations;
    }
    //--
    public LinkedHashMap<TaskState, LinkedHashMap<String, LinkedHashMap<String, Vector<SapforTask>>>> sortTasksByStatesConfigurationsAndGroups() {
        LinkedHashMap<TaskState, LinkedHashMap<String, LinkedHashMap<String, Vector<SapforTask>>>> res = new LinkedHashMap<>();
        //рассортировать задачи по конфигурациям.
        for (TaskState state : TaskState.values()) {
            LinkedHashMap<String, LinkedHashMap<String, Vector<SapforTask>>> tasksByConfigurations = new LinkedHashMap<>();
            res.put(state, tasksByConfigurations);
            //--
            for (SapforTask task : tasks) {
                if (task.state.equals(state)) {
                    LinkedHashMap<String, Vector<SapforTask>> groups_tasks = null;
                    if (tasksByConfigurations.containsKey(task.sapfor_configuration_id)) {
                        groups_tasks = tasksByConfigurations.get(task.sapfor_configuration_id);
                    } else {
                        groups_tasks = new LinkedHashMap<>();
                        tasksByConfigurations.put(task.sapfor_configuration_id, groups_tasks);
                    }
                    Vector<SapforTask> tasks = null;
                    if (groups_tasks.containsKey(task.group_description)) {
                        tasks = groups_tasks.get(task.group_description);
                    } else {
                        tasks = new Vector<>();
                        groups_tasks.put(task.group_description, tasks);
                    }
                    tasks.add(task);
                }
            }
        }
        return res;
    }
}
