package _VisualDVM.TestingSystem.SAPFOR.SapforSettings;
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.Utils.Utils_;
import Common.Visual.DataSetControlForm;
import Common.Visual.Windows.Dialog.DBObjectDialog;
import _VisualDVM.Current;
import _VisualDVM.TestingSystem.SAPFOR.SapforSettings.UI.SapforSettingsFields;
import _VisualDVM.TestingSystem.SAPFOR.SapforSettingsCommand.SapforSettingsCommand;

import java.util.LinkedHashMap;
public class SapforSettingsDBTable extends iDBTable<SapforSettings> {
    public SapforSettingsDBTable() {
        super(SapforSettings.class);
    }
    @Override
    public Current CurrentName() {
        return Current.SapforSettings;
    }
    @Override
    public String getSingleDescription() {
        return "параметры тестирования системы SAPFOR";
    }
    @Override
    public String getPluralDescription() {
        return "параметры тестирования системы SAPFOR";
    }
    @Override
    protected DataSetControlForm createUI() {
        return new DataSetControlForm(this) {
            @Override
            public boolean hasCheckBox() {
                return true;
            }
            @Override
            protected void AdditionalInitColumns() {
                /*
                columns.get(5).setRenderer(TableRenderers.RendererAutoConfiguration);
                columns.get(5).setEditor(TableEditors.EditorAutoConfiguration);
                columns.get(5).setMinWidth(25);
                columns.get(5).setMaxWidth(25);
                columns.get(6).setMaxWidth(300);
                 */
            }
        };
    }
    @Override
    public String[] getUIColumnNames() {
        return new String[]{
                "имя",
                "автор",
                "флаги"
                //"проходы"
        };
    }
    @Override
    public Object getFieldAt(SapforSettings object, int columnIndex) {
        switch (columnIndex) {
            case 2:
                return object.description;
            case 3:
                return object.sender_name;
            case 4:
                return object.flags;
            default:
                return null;
        }
    }
    //-
    @Override
    public DBObjectDialog<SapforSettings, SapforSettingsFields> getDialog() {
        return new DBObjectDialog<SapforSettings, SapforSettingsFields>(SapforSettingsFields.class) {
            @Override
            public int getDefaultHeight() {
                return 415;
            }
            @Override
            public int getDefaultWidth() {
                return 600;
            }
            @Override
            public void validateFields() {
            }
            @Override
            public void fillFields() {
                fields.tfName.setText(Result.description);
                fields.cbFREE_FORM.setSelected(Result.FREE_FORM != 0);
                fields.cbKEEP_DVM_DIRECTIVES.setSelected(Result.KEEP_DVM_DIRECTIVES != 0);
                fields.cbKEEP_SPF_DIRECTIVES.setSelected(Result.KEEP_SPF_DIRECTIVES != 0);
                fields.cbSTATIC_SHADOW_ANALYSIS.setSelected(Result.STATIC_SHADOW_ANALYSIS != 0);
                fields.sMAX_SHADOW_WIDTH.setValue(Result.MAX_SHADOW_WIDTH);
            }
            @Override
            public void ProcessResult() {
                Result.description = fields.tfName.getText();
                Result.FREE_FORM = Utils_.fromBoolean(fields.cbFREE_FORM.isSelected());
                Result.KEEP_DVM_DIRECTIVES = Utils_.fromBoolean(fields.cbKEEP_DVM_DIRECTIVES.isSelected());
                Result.KEEP_SPF_DIRECTIVES = Utils_.fromBoolean(fields.cbKEEP_SPF_DIRECTIVES.isSelected());
                Result.STATIC_SHADOW_ANALYSIS = Utils_.fromBoolean(fields.cbSTATIC_SHADOW_ANALYSIS.isSelected());
                Result.MAX_SHADOW_WIDTH = fields.sMAX_SHADOW_WIDTH.getValue();
                Result.packFlags();
            }
            @Override
            public void SetReadonly() {
                fields.tfName.setEnabled(false);
            }
        };
    }
    @Override
    public LinkedHashMap<Class<? extends DBObject>, FKBehaviour> getFKDependencies() {
        LinkedHashMap<Class<? extends DBObject>, FKBehaviour> res = new LinkedHashMap<>();
        res.put(SapforSettingsCommand.class, new FKBehaviour(FKDataBehaviour.DELETE, FKCurrentObjectBehaviuor.ACTIVE));
        return res;
    }
    @Override
    public Class getMenuBarClass() {
        return SapforSettingsBar.class;
    }
}
