package com.ecep.contract.controller.permission;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.ecep.contract.controller.table.AbstEntityTableTabSkin;
import com.ecep.contract.model.Function;
import com.ecep.contract.model.Permission;
import com.ecep.contract.service.PermissionService;
import com.ecep.contract.util.FxmlPath;
import com.ecep.contract.vm.FunctionViewModel;
import com.ecep.contract.vm.PermissionViewModel;

import javafx.fxml.FXML;
import javafx.scene.control.Tab;
import javafx.scene.control.TableColumn;

@FxmlPath("/ui/employee/function-tab-permission.fxml")
public class FunctionTabSkinPermission
        extends
        AbstEntityTableTabSkin<FunctionWindowController, Function, FunctionViewModel, Permission, PermissionViewModel> {

    @FXML
    public TableColumn<PermissionViewModel, Number> idColumn;
    @FXML
    public TableColumn<PermissionViewModel, String> nameColumn;
    @FXML
    public TableColumn<PermissionViewModel, String> keyColumn;
    @FXML
    public TableColumn<PermissionViewModel, String> descriptionColumn;

    @Autowired
    private PermissionService permissionService;

    public FunctionTabSkinPermission(FunctionWindowController controller) {
        super(controller);
    }

    @Override
    public Tab getTab() {
        return controller.permissionTab;
    }

    @Override
    public PermissionService getViewModelService() {
        if (permissionService == null) {
            permissionService = getBean(PermissionService.class);
        }
        return permissionService;
    }

    @Override
    public void initializeTable() {
        super.initializeTable();
        idColumn.setCellValueFactory(param -> param.getValue().getId());
        nameColumn.setCellValueFactory(param -> param.getValue().getName());
        keyColumn.setCellValueFactory(param -> param.getValue().getKey());
        // descriptionColumn.setCellValueFactory(param ->
        // param.getValue().getDescription());
    }

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

}
