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

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

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 ContractInvoiceTableCell<V> extends AsyncUpdateTableCell<V, Integer, InvoiceVo> {

    /**
     * 创建一个ContractInvoiceTableCell的TableCell工厂，自动获取InvoiceService实例
     *
     * @param <S> 表格行类型
     * @return TableCell工厂回调
     */
    public static <S> Callback<TableColumn<S, Integer>, TableCell<S, Integer>> forTableColumn() {
        return forTableColumn(getBean(InvoiceService.class));
    }

    /**
     * 创建一个ContractInvoiceTableCell的TableCell工厂，使用提供的InvoiceService实例
     *
     * @param <S>     表格行类型
     * @param service InvoiceService实例
     * @return TableCell工厂回调
     */
    public static <S> Callback<TableColumn<S, Integer>, TableCell<S, Integer>> forTableColumn(InvoiceService service) {
        return param -> new ContractInvoiceTableCell<S>(service);
    }

    /**
     * 使用指定的InvoiceService创建ContractInvoiceTableCell
     *
     * @param invoiceService InvoiceService实例
     */
    public ContractInvoiceTableCell(InvoiceService invoiceService) {
        setService(invoiceService);
    }

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

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