package _VisualDVM.TestingSystem.DVM;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.nio.file.Paths;
import java.util.LinkedHashMap;
public class LocalDVMTestingPlanner extends DVMTestingPlanner {
    public LocalDVMTestingPlanner(String[] args) {
        super(args);
    }
    @Override
    protected boolean CheckModules() throws Exception {
        /*
        File modulesDirectory = Paths.get(user.workspace, "modules").toFile();
        File version = new File(modulesDirectory,"version.h");
        int current_version = Constants.Nan;
        int actual_version = Constants.planner_version;
        ///--
        if (version.exists()) {
            try {
                current_version =  Integer.parseInt(FileUtils.readFileToString(version));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        else {
        }
        if (current_version < actual_version) {
            Print("Закачка кода модулей...");
            for (String resource_name : Constants.resourses_names) {
                Print(resource_name);
                File src = Utils.CreateTempResourceFile(resource_name);
                File dst = new File(modulesDirectory, resource_name);
                FileUtils.copyFile(src, dst);
            }
            //--
            Print("Сборка модулей...");
            String modules_log = user.connection.compileModules(modulesDirectory);
            if (!modules_log.isEmpty()) {
                testingPackage.description = modules_log;
                testingPackage.state = TasksPackageState.Aborted;
                return false;
            }
        }
         */
        return true;
    }
    @Override
    public String packageDescription() {
        return "DVM";
    }
    @Override
    protected void TestsSynchronize() throws Exception {
        testingPackage.readJson();
        LinkedHashMap<Integer, File> tests = getTestsFromJson();
        //синхронизировать их.
        for (int test_id : tests.keySet()) {
            File test = tests.get(test_id);
            File testDst = Paths.get(testingPackage.user_workspace, "projects", String.valueOf(test_id)).toFile();
            Print(testDst.getAbsolutePath());
            FileUtils.copyDirectory(test, testDst);
        }
        Finalize("+");
    }
    @Override
    protected void PackageWorkspaceCreation() throws Exception {
    }
    @Override
    protected void AnalyseResults() throws Exception {
    }
    @Override
    protected void PackageStart() throws Exception {
    }
    @Override
    protected boolean CheckNextState() throws Exception {
        return false;
    }
    @Override
    protected void DownloadResults() throws Exception {
    }
    @Override
    protected void Kill() throws Exception {
    }
}
