package com.capgemini.reports.snecmaobjects.part;


import com.capgemini.framework.teamcenter.authent.TcSession;
import com.capgemini.reports.snecmaobjects.ISnecmaObject;
import com.teamcenter.soa.client.model.strong.ItemRevision;

import java.util.ArrayList;
import java.util.List;

import static com.capgemini.framework.teamcenter.object.SnecmaObjectProperties.PV_FOURNISSEURS;

/**
 * Class representing a AlternateRevision or a DETRevision.
 */
public abstract class AbstractAltOrDetRevision extends AbstractPart {
    private static final long serialVersionUID = -1534372886540642285L;
    private final List<AbstractPart> pseudoFolder = new ArrayList<>();

    public AbstractAltOrDetRevision(final TcSession session, final ItemRevision itemRevision) {
        super(session, itemRevision);
    }

    public String[] getLstFournisseurs() {
        return itemRevision.getPropertyObject(PV_FOURNISSEURS).getStringArrayValue();
    }

    /**
     * Adds a {@link ISnecmaObject} to the list of elements found in the pseudo-folder.
     */
    public void addInPseudoFolder(final AbstractPart obj) {
        pseudoFolder.add(obj);
    }

    public void clearPseudoFolder() {
        this.pseudoFolder.clear();
    }

    public List<AbstractPart> getPseudoFolder() {
        return pseudoFolder;
    }

    @Override
    public String toString() {
        String superString = super.toString();
        if (pseudoFolder.isEmpty()) {
            return superString;
        } else {
            return superString + ", pseudoFolder with " + pseudoFolder.size() + " elements";
        }
    }
}
