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

import com.ecep.contract.controller.AbstEntityManagerSkin;
import com.ecep.contract.model.CompanyVendorApprovedList;
import com.ecep.contract.service.CompanyVendorApprovedListService;
import com.ecep.contract.vm.CompanyVendorApprovedListViewModel;

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

public class CompanyVendorApprovedListManagerSkin
        extends AbstEntityManagerSkin<CompanyVendorApprovedList, CompanyVendorApprovedListViewModel, CompanyVendorApprovedListManagerSkin, CompanyVendorApprovedListManagerWindowController> {
    @Setter
    private CompanyVendorApprovedListService service;

    public CompanyVendorApprovedListManagerSkin(CompanyVendorApprovedListManagerWindowController controller) {
        super(controller);
    }

    public CompanyVendorApprovedListService 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(CompanyVendorApprovedListWindowController.class, item);
    }

    @Override
    protected void onTableCreateNewAction(ActionEvent event) {
        CompanyVendorApprovedList list = new CompanyVendorApprovedList();
        CompanyVendorApprovedList saved = service.save(list);

        CompanyVendorApprovedListViewModel viewModel = CompanyVendorApprovedListViewModel.from(saved);

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