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

import javax.swing.*;
import java.util.Comparator;
import java.util.Vector;
public class ServerSapforsDBTable extends iDBTable<ServerSapfor> {
    public ServerSapforsDBTable() {
        super(ServerSapfor.class);
    }
    @Override
    public String getSingleDescription() {
        return "версия SAPFOR";
    }
    @Override
    public String getPluralDescription() {
        return "версии SAPFOR";
    }
    @Override
    protected DataSetControlForm createUI(JPanel mountPanel) {
        return new ServerSapforsForm(this, mountPanel);
    }
    public ServerSapfor getLastDoneVersion() {
        Vector<ServerSapfor> versions = new Vector<>();
        for (ServerSapfor serverSapfor : Data.values()) {
            if (serverSapfor.state.equals(ServerSapforState.Done))
                versions.add(serverSapfor);
        }
        versions.sort(new Comparator<ServerSapfor>() {
            @Override
            public int compare(ServerSapfor o1, ServerSapfor o2) {
                return Long.compare(o1.buildDate, o2.buildDate);
            }
        });
        return versions.isEmpty() ? null : versions.lastElement();
    }
}
