package _VisualDVM.TestingSystem.Common.Group;
import Common.Database.Objects.DBObject;
import Common.Database.Tables.FKBehaviour;
import Common.Database.Tables.FKCurrentObjectBehaviuor;
import Common.Database.Tables.FKDataBehaviour;
import Common.Database.Tables.iDBTable;
import Common.Visual.DataSetControlForm;
import _VisualDVM.Constants;
import _VisualDVM.ProjectData.LanguageName;
import _VisualDVM.TestingSystem.Common.Group.UI.GroupsForm;
import _VisualDVM.TestingSystem.Common.Test.Test;
import _VisualDVM.TestingSystem.DVM.DVMConfigurationGroup.DVMConfigurationGroup;
import _VisualDVM.TestingSystem.SAPFOR.SapforConfigurationGroup.SapforConfigurationGroup;

import javax.swing.*;
import java.util.LinkedHashMap;
//-
public class GroupsDBTable extends iDBTable<Group> {
    public GroupsDBTable() {
        super(Group.class);
    }
    //------------------------------------------------>>>
    @Override
    public String getSingleDescription() {
        return "группа тестов";
    }
    @Override
    public String getPluralDescription() {
        return "группы";
    }
    @Override
    public LinkedHashMap<Class<? extends DBObject>, FKBehaviour> getFKDependencies() {
        LinkedHashMap<Class<? extends DBObject>, FKBehaviour> res = new LinkedHashMap<>();
        res.put(Test.class, new FKBehaviour(FKDataBehaviour.DELETE, FKCurrentObjectBehaviuor.ACTIVE));
        res.put(DVMConfigurationGroup.class, new FKBehaviour(FKDataBehaviour.DELETE, FKCurrentObjectBehaviuor.PASSIVE));
        res.put(SapforConfigurationGroup.class, new FKBehaviour(FKDataBehaviour.DELETE, FKCurrentObjectBehaviuor.PASSIVE));
        return res;
    }
    @Override
    protected DataSetControlForm createUI(JPanel mountPanel) {
        return new GroupsForm(this, mountPanel);
    }
    public boolean containsGroupWithDescription(String description_in) {
        for (Group group : Data.values()) {
            if (group.description.equalsIgnoreCase(description_in))
                return true;
        }
        return false;
    }
    public Group getGroupByDescription(LanguageName language_in, String description_in) {
        for (Group group : Data.values()) {
            if (group.sender_address.equals(Constants.MailAddress) &&
                    group.language.equals(language_in) && group.description.equalsIgnoreCase(description_in))
                return group;
        }
        return null;
    }
    //  CheckCurrent(Log) && Global.mainModule.getAccount().CheckAuthorship(getCurrent().sender_address, Log);
}
