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

import com.ecep.contract.SpringApp;
import com.ecep.contract.service.InvoiceService;
import com.ecep.contract.vo.InvoiceVo;

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

@NoArgsConstructor
public class InvoiceTableCell<V> extends AsyncUpdateTableCell<V, Integer, InvoiceVo> {

    public InvoiceTableCell(InvoiceService invoiceService) {
        setService(invoiceService);
    }

    public static <S> Callback<TableColumn<S, Integer>, TableCell<S, Integer>> forTableColumn() {
        return forTableColumn(SpringApp.getBean(InvoiceService.class));
    }

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

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

    @Override
    public String format(InvoiceVo entity) {
        return entity.getCode();
    }
}
