package _VisualDVM.GlobalData.SapforProfile;
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 Common.Visual.Windows.Dialog.DBObjectDialog;
import _VisualDVM.Current;
import _VisualDVM.GlobalData.SapforProfile.UI.SapforProfileFields;
import _VisualDVM.GlobalData.SapforProfileSetting.SapforProfileSetting;

import java.util.Date;
import java.util.LinkedHashMap;
public class SapforProfilesDBTable extends iDBTable<SapforProfile> {
    public SapforProfilesDBTable() {
        super(SapforProfile.class);
    }
    @Override
    protected DataSetControlForm createUI() {
        return new DataSetControlForm(this);
    }
    @Override
    public String[] getUIColumnNames() {
        return new String[]{
                "Описание",
                "Дата создания"
        };
    }
    @Override
    public Object getFieldAt(SapforProfile object, int columnIndex) {
        switch (columnIndex) {
            case 1:
                return object.description;
            case 2:
                return new Date(object.creationDate);
            default:
                return null;
        }
    }
    @Override
    public Current CurrentName() {
        return Current.SapforProfile;
    }
    @Override
    public DBObjectDialog<SapforProfile, SapforProfileFields> getDialog() {
        return new DBObjectDialog<SapforProfile, SapforProfileFields>(SapforProfileFields.class) {
            @Override
            public int getDefaultHeight() {
                return 250;
            }
            @Override
            public void fillFields() {
                fields.tfDescription.setText(edit ? Result.description : "По умолчанию");
            }
            @Override
            public void ProcessResult() {
                Result.description = fields.tfDescription.getText();
            }
        };
    }
    @Override
    public LinkedHashMap<Class<? extends DBObject>, FKBehaviour> getFKDependencies() {
        LinkedHashMap<Class<? extends DBObject>, FKBehaviour> res = new LinkedHashMap<>();
        res.put(SapforProfileSetting.class, new FKBehaviour(FKDataBehaviour.DELETE, FKCurrentObjectBehaviuor.ACTIVE));
        return res;
    }
    @Override
    public Class getMenuBarClass() {
        return SapforProfilesMenuBar.class;
    }
}
