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

import com.capgemini.reports.definition.r21report.visitors.R21VisitorKeys;
import com.capgemini.reports.snecmaobjects.AbstractSnecmaObject;
import com.capgemini.reports.snecmaobjects.admin.RFAdminAGRevision;
import com.capgemini.reports.snecmaobjects.admin.RFAdminAPRevision;
import com.capgemini.reports.snecmaobjects.admin.RFAdminARevision;
import com.capgemini.reports.snecmaobjects.admin.RFAdminRevision;
import com.capgemini.reports.snecmaobjects.descriptif.DescriptifRevision;
import com.capgemini.reports.snecmaobjects.generic.GenericAssembRevision;
import com.capgemini.reports.snecmaobjects.generic.GenericRevision;
import com.capgemini.reports.snecmaobjects.mockup.MockupRevision;
import com.capgemini.reports.snecmaobjects.part.*;
import com.capgemini.reports.snecmaobjects.product.ProductRevision;
import com.capgemini.reports.snecmaobjects.rf.RFGenericRevision;
import com.capgemini.reports.snecmaobjects.rf.RFPartAssembRevision;
import com.capgemini.reports.snecmaobjects.rf.RFPartRevision;
import com.capgemini.reports.snecmaobjects.supermodel.SuperModelRevision;
import com.capgemini.reports.snecmaobjects.visitor.IReceptorVisitor;

import java.util.EnumMap;
import java.util.Map;

/**
 * Visit a Receptor for the R21 report.
 */
public class R21ReceptorVisitor implements IReceptorVisitor<Map<R21VisitorKeys, String>> {
    private static final long serialVersionUID = -6416544750772729050L;

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(final ProductRevision aProductRev) {
        return getReceptorProperties(aProductRev);
    }

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(final GenericRevision aGenericRev) {
        return getReceptorProperties(aGenericRev);
    }

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(final GenericAssembRevision aGenericAssembRev) {
        return getReceptorProperties(aGenericAssembRev);
    }

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(SuperModelRevision aSuperModelRev) {
        return null;
    }

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(final AlternateRevision aAlternateRev) {
        return getReceptorProperties(aAlternateRev);
    }

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(final DETRevision aDetRev) {
        return getReceptorProperties(aDetRev);
    }

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(final PartAeroRevision aPartAeroRev) {
        return getReceptorProperties(aPartAeroRev);
    }

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(final PartNoAeroRevision aPartNoAeroRev) {
        return getReceptorProperties(aPartNoAeroRev);
    }

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(final PartAssembRevision aPartAssembRev) {
        return getReceptorProperties(aPartAssembRev);
    }

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(final PartMatRevision aPartMatRev) {
        return getReceptorProperties(aPartMatRev);
    }

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(final StandardRevision aStandardRev) {
        return getReceptorProperties(aStandardRev);
    }

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(final RFGenericRevision aRfGenericRev) {
        return getRepereReceptorProperties(aRfGenericRev);
    }

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(final RFPartAssembRevision aRfPartAssembRev) {
        return getRepereReceptorProperties(aRfPartAssembRev);
    }

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(final RFPartRevision aRfPartRev) {
        return getRepereReceptorProperties(aRfPartRev);
    }

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(final RFAdminRevision aRfAdminRev) {
        return new EnumMap<>(R21VisitorKeys.class);
    }

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(final RFAdminARevision aRfAdminARev) {
        return new EnumMap<>(R21VisitorKeys.class);
    }

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(final RFAdminAPRevision aRfAdminAPRev) {
        return new EnumMap<>(R21VisitorKeys.class);
    }

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(final RFAdminAGRevision aRfAdminAGRev) {
        return new EnumMap<>(R21VisitorKeys.class);
    }

    /**
     * Recover the Receptor properties to make a R21 report.
     */
    private Map<R21VisitorKeys, String> getReceptorProperties(final AbstractSnecmaObject aPartOrGeneric) {
        Map<R21VisitorKeys, String> theMap = new EnumMap<>(R21VisitorKeys.class);
        theMap.put(R21VisitorKeys.IDENTIFIANT_RECEPTEUR, aPartOrGeneric.getItemId());
        theMap.put(R21VisitorKeys.REVISION_RECEPTEUR, aPartOrGeneric.getRevisionId());
        theMap.put(R21VisitorKeys.NOM_RECEPTEUR, aPartOrGeneric.getName());

        return theMap;
    }

    /**
     * Recover the Repere Receptor properties to make a R21 report.
     */
    private Map<R21VisitorKeys, String> getRepereReceptorProperties(final AbstractSnecmaObject aRf) {
        Map<R21VisitorKeys, String> theMap = new EnumMap<>(R21VisitorKeys.class);
        theMap.put(R21VisitorKeys.REPERE_FONCTIONNEL_RECEPTEUR, aRf.getName());
        theMap.put(R21VisitorKeys.REVISION_REPERE_FONCTIONNEL_RECEPTEUR, aRf.getRevisionId());
        return theMap;
    }

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(final MockupRevision aMockupRev) {
        // This object is not use in this report
        return null;
    }

    @Override
    public Map<R21VisitorKeys, String> visitReceptor(final DescriptifRevision aDescriptifRev) {
        // This object is not use in this report
        return null;
    }

    @Override
    public Map<R21VisitorKeys, String> emptyRf() {
        return new EnumMap<>(R21VisitorKeys.class);
    }
}
