package _VisualDVM.TestingSystem.SAPFOR.ServerSapfor;
import Common.Database.Tables.iDBTable;
import Common.Visual.DataSetControlForm;
import Common.Visual.Tables.TableRenderers;
import _VisualDVM.Current;
import _VisualDVM.Visual.UI;

import java.util.Comparator;
public class ServerSapforsDBTable extends iDBTable<ServerSapfor> {
    public ServerSapforsDBTable() {
        super(ServerSapfor.class);
    }
    @Override
    public String getSingleDescription() {
        return "SAPFOR";
    }
    @Override
    public String getPluralDescription() {
        return "SAPFOR";
    }
    @Override
    public Current CurrentName() {
        return Current.ServerSapfor;
    }
    @Override
    public String[] getUIColumnNames() {
        return new String[]{"версия", "автор", "дата сборки", "сборка"};
    }
    @Override
    public Object getFieldAt(ServerSapfor object, int columnIndex) {
        switch (columnIndex) {
            case 1:
                return object.version;
            case 2:
                return object.sender_name;
            case 3:
                return object.getBuildDate();
            case 4:
                return object.state;
        }
        return null;
    }
    @Override
    protected DataSetControlForm createUI() {
        return new DataSetControlForm(this) {
            @Override
            protected void AdditionalInitColumns() {
                // columns.get(0).setVisible(false);
                columns.get(3).setRenderer(TableRenderers.RendererDate);
                columns.get(4).setRenderer(TableRenderers.RendererStatusEnum);
            }
            @Override
            public void ShowCurrentObject() throws Exception {
                super.ShowCurrentObject();
                UI.getMainWindow().getTestingWindow().ShowCurrentServerSapfor();
            }
            @Override
            public void ShowNoCurrentObject() throws Exception {
                super.ShowNoCurrentObject();
                UI.getMainWindow().getTestingWindow().ShowNoServerSapfor();
            }
        };
    }
    @Override
    public Comparator<ServerSapfor> getComparator() {
        return new Comparator<ServerSapfor>() {
            @Override
            public int compare(ServerSapfor o1, ServerSapfor o2) {
                return o2.id - o1.id;
            }
        };
        // return Comparator.comparingInt(o -> o.).reversed();
    }
    @Override
    public Class getMenuBarClass() {
        return ServerSapforsBar.class;
    }
}
