package _VisualDVM.TestingSystem.SAPFOR.SapforPackage;
import Common.Database.Tables.iDBTable;
import Common.Visual.DataSetControlForm;
import _VisualDVM.Current;
import _VisualDVM.Global;
import _VisualDVM.Passes.PassCode;
import _VisualDVM.ServerObjectsCache.PackageCache;
import _VisualDVM.ServerObjectsCache.VisualCaches;
import _VisualDVM.TestingSystem.SAPFOR.SapforTasksPackage.UI.SapforPackagesBar;

import java.util.Comparator;
import java.util.Date;

import static Common.Visual.Tables.TableRenderers.*;
public class SapforPackageDBTable extends iDBTable<SapforPackage> {
    public static boolean filterMyOnly = false;
    public static boolean filterActive = false;
    public SapforPackageDBTable() {
        super(SapforPackage.class);
    }
    @Override
    public Current CurrentName() {
        return Current.SapforPackage;
    }
    @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(4).setRenderer(RendererMultiline);
                columns.get(7).setRenderer(RendererProgress);
                columns.get(8).setRenderer(RendererDate);
                columns.get(9).setRenderer(RendererDate);
                columns.get(10).setRenderer(RendererStatusEnum);
            }
            @Override
            public void MouseAction2() throws Exception {
                Global.mainModule.getPass(PassCode.CompareSapforPackages).Do();
            }
        };
    }
    @Override
    public String[] getUIColumnNames() {
        return new String[]{
                "Автор",
                "SAPFOR",
                "Конфигурации",
                "Задач",
                "Ядер",
                "Прогресс",
                "Начало",
                "Изменено",
                "Статус"
        };
    }
    @Override
    public Object getFieldAt(SapforPackage object, int columnIndex) {
        PackageCache cache = (PackageCache) VisualCaches.GetCache(object);
        switch (columnIndex) {
            case 2:
                return object.sender_name;
            case 3:
                return object.version;
            case 4:
                return cache.getConfigurationsDescriptions();
            case 5:
                return object.tasksCount;
            case 6:
                return object.kernels;
            case 7:
                return object.progress;
            case 8:
                return new Date(object.StartDate);
            case 9:
                return new Date(object.ChangeDate);
            case 10:
                return object.state;
            default:
                return null;
        }
    }
    @Override
    public Comparator<SapforPackage> getComparator() {
        return new Comparator<SapforPackage>() {
            @Override
            public int compare(SapforPackage o1, SapforPackage o2) {
                return o2.id - o1.id;
            }
        };
        // return Comparator.comparingInt(o -> o.).reversed();
    }
    @Override
    public Class getMenuBarClass() {
        return SapforPackagesBar.class;
    }
}
