package _VisualDVM.ComponentsServer.BugReport;
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.ComponentsServer.BugReport.UI.BugReportsForm;
import _VisualDVM.ComponentsServer.BugReportFile.BugReportFile;
import _VisualDVM.ComponentsServer.BugReportRecipient.BugReportRecipient;
import _VisualDVM.ComponentsServer.BugReportSetting.BugReportSetting;

import javax.swing.*;
import java.util.LinkedHashMap;
import java.util.Vector;
import java.util.stream.Collectors;
public class BugReportsDBTable extends iDBTable<BugReport> {
    public BugReportsDBTable() {
        super(BugReport.class);
    }
    @Override
    public String getSingleDescription() {
        return "отчёт об ошибке";
    }
    @Override
    public String getPluralDescription() {
        return "отчёты об ошибках";
    }
    @Override
    protected DataSetControlForm createUI(JPanel mountPanel) {
        return new BugReportsForm(this, mountPanel);
    }
    public Vector<BugReport> getAllDrafts() throws Exception {
        return Data.values().stream().filter(bugReport -> bugReport.state.equals(BugReportState.draft)).collect(Collectors.toCollection(Vector::new));
    }
    @Override
    public LinkedHashMap<Class<? extends DBObject>, FKBehaviour> getFKDependencies() {
        LinkedHashMap<Class<? extends DBObject>, FKBehaviour> res = new LinkedHashMap<>();
        res.put(BugReportSetting.class, new FKBehaviour(FKDataBehaviour.DELETE, FKCurrentObjectBehaviuor.PASSIVE));
        res.put(BugReportRecipient.class, new FKBehaviour(FKDataBehaviour.DELETE, FKCurrentObjectBehaviuor.PASSIVE));
        res.put(BugReportFile.class, new FKBehaviour(FKDataBehaviour.DELETE, FKCurrentObjectBehaviuor.ACTIVE));
        return res;
    }
    //-
}
