package com.capgemini.reports.changeobjects.change;

import com.capgemini.framework.teamcenter.authent.TcSession;
import com.teamcenter.soa.client.model.ModelObject;
import com.teamcenter.soa.client.model.strong.ItemRevision;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

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

/**
 * Class representing a TC FPP Revision.
 */
public class FPPRevision extends AbstractChangeObject {
    private static final long serialVersionUID = 2601916478580482L;

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

    public String getOrigineDemande() {
        return itemRevision.getPropertyObject(PV_ORIGINE_DEMANDE).getStringValue();
    }

    /**
     * Method to get Parts inside the apres pseudo folder inside each mod of the sous-modifications pseudo folder
     *
     * @return List<ModelObject>
     */
    public Set<ModelObject> getPartsOfSubModifications() {
        Set<ModelObject> result = new HashSet<>();
        session.loadProperties(itemRevision, CM_IMPLEMENTED_BY);
        List<ModelObject> sousModificationsPseudoFolderContent = itemRevision.getPropertyObject(CM_IMPLEMENTED_BY).getModelObjectListValue();
        for (ModelObject mod : sousModificationsPseudoFolderContent) {
            result.addAll(getPartsFromApresPseudoFolder(mod));
        }
        return result;
    }
}
