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.IComponentVisitor;

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

/**
 * Visit a Component for the R21 report.
 */
public class R21ComponentVisitor implements IComponentVisitor<Map<R21VisitorKeys, String>> {
  private static final long serialVersionUID = -4065760039190332050L;

  private static String formatType(final String type) {
    return type.substring(0, type.length() - " Revision".length());
  }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  /**
   * Recover the Component properties to make a R21 report.
   */
  private Map<R21VisitorKeys, String> getComponentProperties(final AbstractSnecmaObject aPartOrGeneric) {
    Map<R21VisitorKeys, String> theMap = new EnumMap<>(R21VisitorKeys.class);
    theMap.put(R21VisitorKeys.REF_FABRICANT_REF_SNECMA, aPartOrGeneric.getItemId());
    theMap.put(R21VisitorKeys.REVISION_REFERENCE, aPartOrGeneric.getRevisionId());
    theMap.put(R21VisitorKeys.TYPE_REFERENCE, formatType(aPartOrGeneric.getType()));
    theMap.put(R21VisitorKeys.NOM_REFERENCE, aPartOrGeneric.getName());
    return theMap;
  }

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

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

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