package com.ecep.contract.controller.company;

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.IdentityEntity;
import com.ecep.contract.service.CompanyService;
import com.ecep.contract.util.ParamUtils;
import com.ecep.contract.vm.CompanyBasedViewModel;
import com.ecep.contract.vm.CompanyViewModel;
import com.ecep.contract.vm.IdentityViewModel;
import com.ecep.contract.vo.CompanyVo;

public abstract class AbstCompanyTableTabSkin<T extends IdentityEntity, TV extends IdentityViewModel<T>>
        extends AbstEntityTableTabSkin<CompanyWindowController, CompanyVo, CompanyViewModel, T, TV>
        implements TabSkin, TableOfTabSkin<CompanyVo, 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.getCompanyId().set(getEntity().getId());
        }
        return model;
    }

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

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

    @Override
    public ParamUtils.Builder getSpecification(CompanyVo parent) {
        return ParamUtils.builder().equals("company", parent.getId());
    }

}
