package _VisualDVM.TestingSystem.SAPFOR.SapforSettingsCommand;
import Common.Visual.UI_;
import _VisualDVM.Current;
import Common.Database.Tables.iDBTable;
import Common.Visual.DataSetControlForm;
import Common.Visual.Windows.Dialog.DBObjectDialog;
import _VisualDVM.Global;
import _VisualDVM.TestingSystem.SAPFOR.SapforSettings.SapforSettings;
import _VisualDVM.TestingSystem.SAPFOR.SapforSettings.UI.SapforSettingsCommandFields;
import Visual_DVM_2021.Passes.PassCode;

import java.util.Vector;
public class SapforSettingsCommandsDBTable extends iDBTable<SapforSettingsCommand> {
    public SapforSettingsCommandsDBTable() {
        super(SapforSettingsCommand.class);
    }
    @Override
    public String getSingleDescription() {
        return "команда";
    }
    @Override
    public String getPluralDescription() {
        return "команды";
    }
    @Override
    public String[] getUIColumnNames() {
        return new String[]{
                "Проход"
        };
    }
    @Override
    public Object getFieldAt(SapforSettingsCommand object, int columnIndex) {
        switch (columnIndex) {
            case 2:
                return object.passCode.getDescription();
            default:
                return null;
        }
    }
    @Override
    public Current CurrentName() {
        return Current.SapforSettingsCommand;
    }
    @Override
    protected DataSetControlForm createUI() {
        return new DataSetControlForm(this) {
            @Override
            public boolean hasCheckBox() {
                return true;
            }
            @Override
            protected void AdditionalInitColumns() {
                //columns.get(0).setVisible(false);
            }
        };
    }
    @Override
    public DBObjectDialog<SapforSettingsCommand, SapforSettingsCommandFields> getDialog() {
        return new DBObjectDialog<SapforSettingsCommand, SapforSettingsCommandFields>(SapforSettingsCommandFields.class) {
            @Override
            public int getDefaultHeight() {
                return 250;
            }
            @Override
            public void fillFields() {
                UI_.TrySelect(fields.cbPassCode, Result.passCode);
            }
            @Override
            public void ProcessResult() {
                Result.passCode = (PassCode) fields.cbPassCode.getSelectedItem();
                Result.sapforsettings_id = Global.mainModule.getSapforSettings().id;
            }
        };
    }
    //--
    public Vector<PassCode> getCodes(SapforSettings sapforSettings) {
        Vector<PassCode> res = new Vector<>();
        for (SapforSettingsCommand command : Data.values()) {
            if (command.sapforsettings_id == sapforSettings.id)
                res.add(command.passCode);
        }
        return res;
    }
}
