package TestingSystem.Common.TestingPackage;
import Common.Constants;
import Common.Database.DBObject;
import Common.Database.riDBObject;
import Common.Utils.Utils;
import TestingSystem.Common.TasksPackageState;
import com.sun.org.glassfish.gmbal.Description;

import java.io.File;
public abstract class TestingPackage<J> extends riDBObject {
    public String PID = "";
    public int tasksCount = 0; //Общее число задач
    //--
    public int kernels = 1;
    public int needsEmail = 0;
    //---
    public String version = ""; //версия тестируемого объекта
    public String drv = ""; //пусть к исполняемому файлы тестируемого объекта
    //--
    public int progress = 0; //прогресс выполнения
    public long StartDate = 0;
    public long ChangeDate = 0;
    public TasksPackageState state = TasksPackageState.Draft;
    //--
    @Override
    public void SynchronizeFields(DBObject src) {
        super.SynchronizeFields(src);
        TestingPackage tp = (TestingPackage) src;
        //--
        tasksCount = tp.tasksCount;
        needsEmail = tp.needsEmail;
        version = tp.version;
        drv = tp.drv;
        PID = tp.PID;
        kernels = tp.kernels;
        progress = tp.progress;
        StartDate = tp.StartDate;
        ChangeDate = tp.ChangeDate;
        state = tp.state;
    }
    public TestingPackage(TestingPackage p) {
        SynchronizeFields(p);
    }
    public TestingPackage() {
    }
    public File getLocalWorkspace() {
        return new File(getHomeDirectory(), String.valueOf(id));
    }
    public boolean isLoaded() {
        return new File(getLocalWorkspace(), Constants.LOADED).exists();
    }
    //------------------------
    @Description("IGNORED")
    public J package_json = null;
    public abstract Class getJsonClass();
    public abstract File getHomeDirectory();
    public File getJsonFile() {
        return new File(getLocalWorkspace(), "package_json");
    }
    public File getLoadedFile() {
        return new File(getLocalWorkspace(), Constants.LOADED);
    }
    public void saveJson() throws Exception {
        Utils.jsonToFile(package_json, getJsonFile());
    }
    public void readJson() throws Exception {
        package_json = (J) Utils.jsonFromFile(getJsonFile(), getJsonClass());
    }
    public void destructor() {
        package_json = null;
    }
}
