package com.ecep.contract.controller.vendor.approved_list;

import com.ecep.contract.controller.AbstEntityManagerSkin;
import com.ecep.contract.service.VendorApprovedService;
import com.ecep.contract.vo.VendorApprovedVo;
import com.ecep.contract.vm.CompanyVendorApprovedListViewModel;

import javafx.event.ActionEvent;
import javafx.scene.control.SelectionMode;
import lombok.Setter;

public class VendorApprovedListManagerSkin
        extends AbstEntityManagerSkin<VendorApprovedVo, CompanyVendorApprovedListViewModel, VendorApprovedListManagerSkin, VendorApprovedListManagerWindowController> {
    @Setter
    private VendorApprovedService service;

    public VendorApprovedListManagerSkin(VendorApprovedListManagerWindowController controller) {
        super(controller);
    }

    public VendorApprovedService getService() {
        return service;
    }


    @Override
    public void initializeTable() {
        controller.idColumn.setCellValueFactory(param -> param.getValue().getId());
        controller.titleColumn.setCellValueFactory(param -> param.getValue().getTitle());
        controller.publishDateColumn.setCellValueFactory(param -> param.getValue().getPublishDate());
        controller.descriptionColumn.setCellValueFactory(param -> param.getValue().getDescription());

        getTableView().getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    }

    @Override
    protected void onTableRowDoubleClickedAction(CompanyVendorApprovedListViewModel item) {
        showInOwner(VendorApprovedListWindowController.class, item);
    }

    @Override
    protected void onTableCreateNewAction(ActionEvent event) {
        VendorApprovedVo list = new VendorApprovedVo();
        CompanyVendorApprovedListViewModel viewModel = CompanyVendorApprovedListViewModel.from(list);

        dataSet.add(viewModel);
        showInOwner(VendorApprovedListWindowController.class, viewModel);
    }
}
