package SapforTestingSystem.SapforTasksPackage;
import Common.Current;
import Common.Database.*;
import Common.UI.DataSetControlForm;
import SapforTestingSystem.SapforTask.SapforTask;

import java.util.Date;
import java.util.LinkedHashMap;

import static Common.UI.Tables.TableRenderers.RendererDate;
import static Common.UI.Tables.TableRenderers.RendererStatusEnum;
public class SapforTasksPackagesDBTable extends DBTable<String, SapforTasksPackage> {
    public SapforTasksPackagesDBTable() {
        super(String.class, SapforTasksPackage.class);
    }
    @Override
    public Current CurrentName() {
        return Current.SapforTasksPackage;
    }
    @Override
    public String getSingleDescription() {
        return "пакет задач Sapfor";
    }
    @Override
    public String getPluralDescription() {
        return "пакеты задач Sapfor";
    }
    @Override
    protected DataSetControlForm createUI() {
        return new DataSetControlForm(this) {
            @Override
            protected void AdditionalInitColumns() {
                columns.get(5).setRenderer(RendererDate);
                columns.get(6).setRenderer(RendererDate);
                columns.get(7).setRenderer(RendererStatusEnum);
            }
        };
    }
    @Override
    public String[] getUIColumnNames() {
        return new String[]{
                "SAPFOR",
                "Тесты",
                "Задач",
                "Ядер",
                "Начало",
                "Изменено",
                "Статус"
        };
    }
    @Override
    public Object getFieldAt(SapforTasksPackage object, int columnIndex) {
        switch (columnIndex) {
            case 1:
                return object.sapfor_version;
            case 2:
                return object.testsNames;
            case 3:
                return object.tasksCount;
            case 4:
                return object.kernels;
            case 5:
                return new Date(object.StartDate);
            case 6:
                return new Date(object.ChangeDate);
            case 7:
                return object.state;
            default:
                return null;
        }
    }

    @Override
    public LinkedHashMap<Class<? extends DBObject>, FKBehaviour> getFKDependencies() {
        LinkedHashMap<Class<? extends DBObject>, FKBehaviour> res = new LinkedHashMap<>();
        res.put(SapforTask.class, new FKBehaviour(FKDataBehaviour.DELETE, FKCurrentObjectBehaviuor.ACTIVE));
        return res;
    }
}
