package _VisualDVM.ProjectData.Messages.Recommendations;
import Common.Database.Tables.iDBTable;
import Common.Visual.DataSetControlForm;
import _VisualDVM.Passes.PassCode;
import _VisualDVM.ProjectData.Messages.Recommendations.UI.RecommendationsForm;

import javax.swing.*;
public class RecommendationsDBTable extends iDBTable<MessageRecommendation> {
    //group=1 - настройка
    //group=2 - преобразование
    public RecommendationsDBTable() {
        super(MessageRecommendation.class);
        //   setUIContent(UI.getMainWindow().errorsPanel);
    }
    @Override
    protected DataSetControlForm createUI(JPanel mountPanel) {
        return new RecommendationsForm(this, mountPanel);
    }
    public void addRecommendation(int group_in) {
        MessageRecommendation result = null;
        switch (group_in) {
            /*
            case 1013:
                //процедура. понять как извлекать ее из сообщения, и сунуть как аргумент преобразованию.
                break;
             */
            case 1015:
                result = new MessageRecommendation(PassCode.SPF_RemoveUnusedFunctions);
                break;
            case 1018:
                result = new MessageRecommendation(PassCode.SPF_LoopEndDoConverterPass);
                break;
            case 1020:
                result = new MessageRecommendation("Учитывать DVM директивы", "1");
                break;
            case 1027:
            case 1060:
                result = new MessageRecommendation(PassCode.SPF_CorrectCodeStylePass);
                break;
            case 1041:
            case 3012:
            case 3013:
            case 3014:
            case 3015:
            case 3017:
            case 3018:
                result = new MessageRecommendation(PassCode.SPF_ResolveParallelRegionConflicts);
                break;
            case 1061:
                result = new MessageRecommendation(PassCode.SPF_InsertIncludesPass);
                break;
            case 3020:
                result = new MessageRecommendation(PassCode.SPF_DuplicateFunctionChains);
                break;
        }
        MessageRecommendation finalResult = result;
        if ((result != null) && (Data.values().stream().noneMatch(recommendation -> recommendation.isMatch(finalResult)))) {
            try {
                getDb().Insert(result);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
}
