package com.ecep.contract.controller.company;

import java.util.Map;

import com.ecep.contract.controller.tab.TabSkin;
import com.ecep.contract.controller.table.AbstEntityTableTabSkin;
import com.ecep.contract.controller.table.TableOfTabSkin;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.IdentityEntity;
import com.ecep.contract.service.CompanyService;
import com.ecep.contract.vm.CompanyBasedViewModel;
import com.ecep.contract.vm.CompanyViewModel;
import com.ecep.contract.vm.IdentityViewModel;

public abstract class AbstCompanyTableTabSkin<T extends IdentityEntity, TV extends IdentityViewModel<T>>
        extends AbstEntityTableTabSkin<CompanyWindowController, Company, CompanyViewModel, T, TV>
        implements TabSkin, TableOfTabSkin<Company, T, TV> {


    public AbstCompanyTableTabSkin(CompanyWindowController controller) {
        super(controller);
        viewModel = controller.getViewModel();
    }

    @Override
    protected TV createNewViewModel() {
        TV model = super.createNewViewModel();
        if (model instanceof CompanyBasedViewModel m) {
            m.getCompany().set(getEntity());
        }
        return model;
    }

    protected CompanyService getCompanyService() {
        return getParentService();
    }

    protected CompanyService getParentService() {
        return controller.getViewModelService();
    }

    @Override
    public Map<String, Object> getSpecification(Company parent) {
        Map<String, Object> params = getSpecification();
        params.put("company", parent.getId());
        return params;
    }

}
