package com.ecep.contract.controller.table.cell;

import static com.ecep.contract.SpringApp.getBean;

import com.ecep.contract.service.ProjectService;
import com.ecep.contract.vo.ProjectVo;

import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.util.Callback;
import lombok.NoArgsConstructor;

@NoArgsConstructor
public class ProjectTableCell<V> extends AsyncUpdateTableCell<V, Integer, ProjectVo> {
    public static <S> Callback<TableColumn<S, Integer>, TableCell<S, Integer>> forTableColumn() {
        return forTableColumn(getBean(ProjectService.class));
    }

    public static <S> Callback<TableColumn<S, Integer>, TableCell<S, Integer>> forTableColumn(ProjectService service) {
        return param -> new ProjectTableCell<S>(service);
    }

    public ProjectTableCell(ProjectService projectService) {
        setService(projectService);
    }

    @Override
    protected ProjectService getServiceBean() {
        return getBean(ProjectService.class);
    }

    @Override
    public String format(ProjectVo entity) {
        return entity.getCode() + " " + entity.getName();
    }
}
