package com.ecep.contract.controller.project;

import java.util.Map;

import com.ecep.contract.controller.tab.TabSkin;
import com.ecep.contract.controller.table.AbstEntityTableTabSkin;
import com.ecep.contract.model.IdentityEntity;
import com.ecep.contract.model.Project;
import com.ecep.contract.service.ProjectService;
import com.ecep.contract.vm.IdentityViewModel;
import com.ecep.contract.vm.ProjectBasedViewModel;
import com.ecep.contract.vm.ProjectViewModel;

public abstract class AbstProjectTableTabSkin<T extends IdentityEntity, TV extends IdentityViewModel<T>>
        extends AbstEntityTableTabSkin<ProjectWindowController, Project, ProjectViewModel, T, TV>
        implements TabSkin {

    public AbstProjectTableTabSkin(ProjectWindowController controller) {
        super(controller);
    }

    public ProjectService getProjectService() {
        return controller.projectService;
    }

    @Override
    protected TV createNewViewModel() {
        TV model = super.createNewViewModel();
        if (model instanceof ProjectBasedViewModel m) {
            m.getProject().set(getEntity());
        }
        return model;
    }

    @Override
    public Map<String, Object> getSpecification(Project parent) {
        Map<String, Object> params = getSpecification();
        params.put("project", parent.getId());
        return params;
    }
}
