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

import com.ecep.contract.SpringApp;
import com.ecep.contract.service.IEntityService;
import com.ecep.contract.service.VendorCatalogService;
import com.ecep.contract.vo.VendorCatalogVo;

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

@NoArgsConstructor
public class VendorCatalogTableCell<T> extends AsyncUpdateTableCell<T, Integer, VendorCatalogVo> {
    public static <S> Callback<TableColumn<S, Integer>, TableCell<S, Integer>> forTableColumn() {
        return forTableColumn(SpringApp.getBean(VendorCatalogService.class));
    }

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

    public VendorCatalogTableCell(VendorCatalogService service) {
        setService(service);
    }

    @Override
    protected IEntityService<VendorCatalogVo> getServiceBean() {
        return SpringApp.getBean(VendorCatalogService.class);
    }

    @Override
    protected boolean isInitialized(VendorCatalogVo proxy) {
        if (!super.isInitialized(proxy)) {
            return false;
        }
        return false;
    }

    @Override
    protected VendorCatalogVo initialize() {
        VendorCatalogVo catalog = super.initialize();
        return catalog;
    }

    @Override
    public String format(VendorCatalogVo catalog) {
        if (catalog == null) {
            return "#" + getItem() + " -";
        }
        return catalog.getName();
    }
}