package _VisualDVM.TestingSystem.Common.Group;
import Common.Database.Objects.DBObject;
import Common.Database.Objects.riDBObject;
import Common.Utils.Utils_;
import Common.Visual.UI;
import _VisualDVM.Global;
import _VisualDVM.ProjectData.Files.ProjectFile;
import _VisualDVM.ProjectData.LanguageName;
import _VisualDVM.TestingSystem.Common.Test.TestType;
import _VisualDVM.Utils;
import com.sun.org.glassfish.gmbal.Description;

import java.util.LinkedHashMap;
import java.util.Vector;
public class Group extends riDBObject {
    @Description("DEFAULT 'Default'")
    public TestType type = TestType.Default;
    @Description("DEFAULT 'fortran'")
    public LanguageName language = LanguageName.fortran;
    public Group(Group group) {
        this.SynchronizeFields(group);
    }
    public Group() {
    }
    //--
    //-
    public static void generateForLanguage(
            String dvm_drv,
            LinkedHashMap<LanguageName, Vector<ProjectFile>> programs,
            LanguageName language,
            Vector<String> titles,
            Vector<String> objects,
            Vector<String> bodies,
            String flags_in
    ) {
        if (!programs.get(language).isEmpty()) {
            String LANG_ = language.toString().toUpperCase() + "_";
            Vector<String> module_objects = new Vector<>();
            String module_body = "";
            int i = 1;
            for (ProjectFile program : programs.get(language)) {
                //--
                String object = Utils_.DQuotes(language + "_" + i + ".o");
                module_objects.add(object);
                module_body +=
                        object + ":\n" +
                                "\t" +
                                String.join(" ",
                                        Utils.MFVar(LANG_ + "COMMAND"),
                                        Utils.MFVar(LANG_ + "FLAGS"),
                                        program.getStyleOptions(),
                                        "-c",
                                        program.getQSourceName(),
                                        "-o",
                                        object + "\n\n"
                                );
                ++i;
            }
            titles.add(String.join("\n",
                    LANG_ + "COMMAND=" + Utils_.DQuotes(dvm_drv) + " " +
                            language.getDVMCompile(),
                    LANG_ + "FLAGS=" + flags_in,
                    LANG_ + "OBJECTS=" + String.join(" ", module_objects),
                    ""
            ));
            objects.add(Utils.MFVar(LANG_ + "OBJECTS"));
            bodies.add(module_body);
        }
    }
    //--
    public String getSummary() {
        return description + " " + language.getDescription();
    }
    //-
    @Override
    public void SynchronizeFields(DBObject src) {
        super.SynchronizeFields(src);
        Group g = (Group) src;
        type = g.type;
        language = g.language;
    }
    @Override
    public void select(boolean flag) {
        super.select(flag);
        if (UI.isActive())
            Global.mainModule.getUI().getMainWindow().ShowCheckedTestsCount();
    }
}
