package _VisualDVM.TestingSystem.DVM.DVMSettings;
import Common.Database.Objects.DBObject;
import _VisualDVM.GlobalData.RunConfiguration.RunConfiguration;
import _VisualDVM.TestingSystem.Common.Settings.Settings;
import com.sun.org.glassfish.gmbal.Description;

import java.util.Vector;
public class DVMSettings extends Settings {
    @Description("DEFAULT 0")
    public int Is_DVM_STAT = 0; //флаг вмест usr par, которые не использовались.
    //---
    public int cube = 0; //
    public int max_proc_count = 4;
    public int min_dim_proc_count = 1;
    public int max_dim_proc_count = 4;
    //--
    @Description("IGNORE")
    public String packedCompilationOptionsJson = "";
    @Description("IGNORE")
    public String packedRunEnvironmentValuesJson = "";
    //--
    public DVMSettings() {
    }
    public DVMSettings(DVMSettings src) {
        this.SynchronizeFields(src);
    }
    @Override
    public void SynchronizeFields(DBObject src) {
        super.SynchronizeFields(src);
        DVMSettings c = (DVMSettings) src;
        Is_DVM_STAT = c.Is_DVM_STAT;
        //-
        cube = c.cube;
        max_proc_count = c.max_proc_count;
        min_dim_proc_count = c.min_dim_proc_count;
        max_dim_proc_count = c.max_dim_proc_count;
    }
    public String printUsrPar() {
        return "Is_DVM_STAT=" + Is_DVM_STAT;
    }
    public Vector<String> getMatrixes(int testDim) {
        Vector<Vector<Integer>> res_ = new Vector<>();
        Vector<String> res = new Vector<>();
        if ((max_proc_count == 0) || (min_dim_proc_count == 0 && max_dim_proc_count == 0)) {
            res.add("");
        } else {
            if (testDim > 0) {
                Vector<String> min_border = new Vector<>();
                Vector<String> max_border = new Vector<>();
                for (int i = 1; i <= testDim; ++i) {
                    min_border.add(String.valueOf(min_dim_proc_count));
                    max_border.add(String.valueOf(max_dim_proc_count));
                }
                Vector<Integer> from = RunConfiguration.getBounds(String.join(" ", min_border));
                Vector<Integer> to = RunConfiguration.getBounds(String.join(" ", max_border));
                if (from.size() != to.size()) {
                    return res;
                }
                if (from.size() != testDim) {
                    return res;
                }
                //1 стадия. заполнение.
                for (int j = from.get(0); j <= to.get(0); ++j) {
                    Vector<Integer> m = new Vector<>();
                    res_.add(m);
                    m.add(j);
                }
                //---
                if (testDim > 1) RunConfiguration.gen_rec(from, to, res_, 1, testDim, cube == 1);
                for (Vector<Integer> m : res_) {
                    Vector<String> ms = new Vector<>();
                    int proc = 1;
                    for (int i : m) {
                        ms.add(String.valueOf(i));
                        proc *= i;
                    }
                    if (proc <= max_proc_count)
                        res.add(String.join(" ", ms));
                }
            } else res.add("");
        }
        return res;
    }
    public String getParamsText() {
        return "Is_DVM_STAT=" + Is_DVM_STAT;
    }
}

