package com.ecep.contract.controller.permission;

import com.ecep.contract.controller.AbstEntityManagerSkin;
import com.ecep.contract.controller.ManagerSkin;
import com.ecep.contract.controller.table.EditableEntityTableTabSkin;
import com.ecep.contract.model.EmployeeRole;
import com.ecep.contract.service.PermissionService;
import com.ecep.contract.vm.EmployeeRoleViewModel;

import javafx.scene.control.cell.CheckBoxTableCell;
import lombok.Setter;

public class EmployeeRoleManagerSkin
        extends
        AbstEntityManagerSkin<EmployeeRole, EmployeeRoleViewModel, EmployeeRoleManagerSkin, EmployeeRoleManagerWindowController>
        implements ManagerSkin, EditableEntityTableTabSkin<EmployeeRole, EmployeeRoleViewModel> {

    @Setter
    private PermissionService permissionService;

    public EmployeeRoleManagerSkin(EmployeeRoleManagerWindowController controller) {
        super(controller);
    }

    @Override
    public void initializeTable() {
        controller.idColumn.setCellValueFactory(param -> param.getValue().getId());
        controller.codeColumn.setCellValueFactory(param -> param.getValue().getCode());
        controller.nameColumn.setCellValueFactory(param -> param.getValue().getName());
        controller.systemAdministratorColumn.setCellValueFactory(param -> param.getValue().getSystemAdministrator());
        controller.systemAdministratorColumn.setCellFactory(param -> new CheckBoxTableCell<>());
        controller.managerColumn.setCellValueFactory(param -> param.getValue().getManager());
        controller.managerColumn.setCellFactory(CheckBoxTableCell.forTableColumn(controller.managerColumn));
        controller.activeColumn.setCellValueFactory(param -> param.getValue().getActive());
        controller.activeColumn.setCellFactory(CheckBoxTableCell.forTableColumn(controller.activeColumn));
    }

    @Override
    protected void onTableRowDoubleClickedAction(EmployeeRoleViewModel item) {
        EmployeeRoleWindowController.show(item, controller.table.getScene().getWindow());
    }

    protected PermissionService getPermissionService() {
        if (permissionService == null) {
            permissionService = getBean(PermissionService.class);
        }
        return permissionService;
    }

}
