package com.capgemini.reports.definition.r21report.visitors.bomlineholder;

import com.capgemini.reports.bomlineholder.BOMLineHolder;
import com.capgemini.reports.bomlineholder.visitor.AbstractBOMLineHolderVisitor;
import com.capgemini.reports.definition.r21report.visitors.R21VisitorKeys;
import com.capgemini.reports.definition.r21report.visitors.snecmaobject.R21ComponentVisitor;
import com.capgemini.reports.definition.r21report.visitors.snecmaobject.R21ReceptorVisitor;
import com.capgemini.reports.releasestatus.EffectivityBehaviourHelper;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * Visitor of an expansion of BOMLineHolder for the R21 report.
 */
@Slf4j
@EqualsAndHashCode(callSuper = true)
public class R21BOMLineHolderVisitor extends AbstractBOMLineHolderVisitor<R21VisitorKeys, String> {
    private static final long serialVersionUID = -2637811314864998456L;

    public R21BOMLineHolderVisitor() {
        super(new R21ReceptorVisitor(), new R21ComponentVisitor(), EffectivityBehaviourHelper.visitOnlyUnitManagedParts(),
                new R21AltOrDetBehaviour(), true, false, false);
    }

    @Override
    protected Map<R21VisitorKeys, String> visitThisReceptor(final BOMLineHolder aBomLine) {
        return aBomLine.getSnecmaObject().accept(receptorVisitor);
    }

    @Override
    protected Map<R21VisitorKeys, String> visitThisComponent(final BOMLineHolder aBomLine) {
        return aBomLine.getSnecmaObject().accept(componentVisitor);
    }

    @Override
    protected void mergeReceptorAndRepereReceptor(final Map<R21VisitorKeys, String> aReceptor, final Map<R21VisitorKeys, String> aRepereReceptor) {
        aReceptor.putAll(aRepereReceptor);
    }

    @Override
    protected void mergeComponentAndRepereComponent(final Map<R21VisitorKeys, String> aComponent, final Map<R21VisitorKeys, String> aRepereComponent) {
        aComponent.putAll(aRepereComponent);
    }

    @Override
    protected void mergeRepereReceptorandAdmin(final Map<R21VisitorKeys, String> aRepereReceptor, final Map<R21VisitorKeys, String> anAdmin) {
        // No used in the R21 report
    }

    @Override
    protected void mergeRepereComponentandAdmin(final Map<R21VisitorKeys, String> aRepereComponent, final Map<R21VisitorKeys, String> anAdmin) {
        // No used in the R21 report
    }

    @Override
    protected void addToReport(final Map<R21VisitorKeys, String> aReceptor, final Map<R21VisitorKeys, String> aComponent) {
        // Put the Receptor and Repere Receptor in the Component and modify the Component
        // Do not modify the receptor
        aComponent.putAll(aReceptor);

        // Add to the R21 report
        theReportTable.add(aComponent);
    }

    @Override
    protected void visitSpecificFirstLine(final BOMLineHolder bomHolder) {
        // No use for R21 report
    }
}
