package com.capgemini.reports.bomlineholder.flattener.line;

import com.capgemini.framework.common.StringHelper;
import com.capgemini.framework.teamcenter.object.types.SnecmaObjectTypes;
import com.capgemini.reports.bomlineholder.BOMLineHolder;
import com.capgemini.reports.snecmaobjects.ISnecmaObject;
import com.capgemini.reports.snecmaobjects.generic.AbstractGenericRevision;
import com.capgemini.reports.snecmaobjects.part.AbstractPart;
import com.capgemini.reports.snecmaobjects.product.ProductRevision;
import lombok.Getter;

/**
 * Represents a top object. As a top object, it does not have a fater Receptor.
 *
 * @param <U> a Transformer object producing results of type T
 * @param <T> the result of a transformation by object of type U
 */
@Getter
public abstract class AbstractTopLine<T, U> implements SnecmaLine<T, U> {

    private final BOMLineHolder bomLine;
    private final ISnecmaObject bomLineObject;
    private final int lineNumber;

    /**
     * Builds a top Line form its {@link BOMLineHolder}.
     *
     * @param topBomLine a top {@link BOMLineHolder}
     * @param lineNum    the line number in the bom
     */
    public AbstractTopLine(final BOMLineHolder topBomLine, final int lineNum) {
        this.bomLine = topBomLine;
        this.bomLineObject = topBomLine.getSnecmaObject();
        this.lineNumber = lineNum;
    }

    @Override
    public int compareTo(final SnecmaLine<T, U> other) {
        return getLineId().compareTo(other.getLineId());
    }

    @Override
    public String toString() {
        return "TopLine(Bom=" + bomLine.getUid() + ", obj=" + bomLineObject.getItemId() + ")";
    }

    @Override
    public String getLineId() {
        return bomLineObject.getItemId();
    }

    @Override
    public String getIDReceptor() {
        return StringHelper.EMPTY;
    }

    @Override
    public String getNameReceptor() {
        return StringHelper.EMPTY;
    }

    @Override
    public String getRevisionReceptor() {
        return StringHelper.EMPTY;
    }

    @Override
    public String getRepereName() {
        return StringHelper.EMPTY;
    }

    @Override
    public String getRepereRevision() {
        return StringHelper.EMPTY;
    }

    @Override
    public String getResponsableRepere() {
        return StringHelper.EMPTY;
    }

    @Override
    public String getSuiviMontage() {
        return StringHelper.EMPTY;
    }

    @Override
    public String getIDComponent() {
        return bomLineObject.getItemId();
    }

    @Override
    public String getIDRevisionComponent() {
        return bomLineObject.getRevisionId();
    }

    @Override
    public String getTypeReference() {
        String typeReference;
        if (bomLineObject.isPart()) {
            typeReference = PartTypeExtractorHelper.extractType(bomLineObject);
        } else if (bomLineObject.isProduct()) {
            typeReference = "Produit";
        } else if (bomLineObject.isGeneric()) {
            String type = bomLineObject.getType();
            if (SnecmaObjectTypes.GENERIC_REVISION.equals(type)) {
                typeReference = "Générique";
            } else if (SnecmaObjectTypes.GENERIC_ASSEMB_REVISION.equals(type)) {
                typeReference = "Générique Montage";
            } else {
                typeReference = StringHelper.EMPTY;
            }
        } else {
            typeReference = StringHelper.EMPTY;
        }
        return typeReference;
    }

    @Override
    public String getNameReference() {
        return bomLineObject.getName();
    }

    @Override
    public String getReferenceConceptor() {
        return StringHelper.EMPTY;
    }

    @Override
    public String getReferenceTransposed() {
        return StringHelper.EMPTY;
    }

    @Override
    public String getReferenceAssociated() {
        return StringHelper.EMPTY;
    }

    @Override
    public String getResponsableConception() {
        return StringHelper.EMPTY;
    }

    @Override
    public String getArticleGestion() {
        return StringHelper.EMPTY;
    }

    @Override
    public String getClassement() {
        return StringHelper.EMPTY;
    }

    @Override
    public String getSuiviUtilisation() {
        return StringHelper.EMPTY;
    }

    @Override
    public String getSuiviDureeVie() {
        return StringHelper.EMPTY;
    }

    @Override
    public String[] getSuppliersList() {
        return new String[0];
    }

    @Override
    public String getALT() {
        return bomLine.getBomAlt();
    }

    @Override
    public String getSB() {
        return bomLine.getBomSb();
    }

    @Override
    public String getQuantiteCumulee() {
        return bomLine.getBomQtyCumul();
    }

    @Override
    public String getPanachage() {
        return bomLine.getBomPanache();
    }

    @Override
    public String getQuantite() {
        return bomLine.getBomQty();
    }

    @Override
    public String getMaquetteInterneExterne() {
        return StringHelper.EMPTY;
    }

    @Override
    public Double getMass() {
        return null;
    }

    @Override
    public String getMassUnit() {
        return StringHelper.EMPTY;
    }

    @Override
    public String getDesignationENG() {
        String designation;
        if (bomLineObject.isPart()) {
            designation = ((AbstractPart) bomLineObject).getDesignationEN();
        } else if (bomLineObject.isGeneric()) {
            designation = ((AbstractGenericRevision) bomLineObject).getDesignationEN();
        } else if (bomLineObject.isProduct()) {
            designation = ((ProductRevision) bomLineObject).getDesignationEN();
        } else {
            designation = StringHelper.EMPTY;
        }
        return designation;
    }
}
