package com.capgemini.reports.definition.r24report;

import com.capgemini.framework.teamcenter.authent.TcSession;
import com.capgemini.framework.teamcenter.exceptions.EmptyNomenclatureException;
import com.capgemini.framework.teamcenter.object.types.SnecmaObjectTypes;
import com.capgemini.framework.teamcenter.resolution.filtering.ITcTypeFilter;
import com.capgemini.framework.teamcenter.resolution.filtering.TcTypeInclusionFilter;
import com.capgemini.reports.bomlineholder.BOMLineHolder;
import com.capgemini.reports.bomlineholder.BOMLineHolderHelper;
import com.capgemini.reports.exceptions.InvalidInputException;
import com.capgemini.reports.exceptions.MalformedNomenclatureException;
import com.capgemini.reports.teamcenter.resolution.IBOMLineExplorer;
import com.capgemini.reports.teamcenter.resolution.structureservice.SingleStructureServiceCaller;

/**
 * Explorer of {@link BOMLineHolder}s used in {@link SingleStructureServiceCaller} for R24 report.<br/>
 * Thanks to this class, the SINGLE resolution structure could carry on and the Part Number could be taken. <br>
 * The Rf Generic is returned, and its children Part Aero / RF Admin and Descriptif are loaded
 */
public class R24BOMLineExplorer implements IBOMLineExplorer {

    private static final ITcTypeFilter FILTER_PART_ADMIN_DESCRIPTION = new TcTypeInclusionFilter(SnecmaObjectTypes.PART_AERO_REVISION, SnecmaObjectTypes.RF_ADMIN_REVISION, SnecmaObjectTypes.DESCRIPTIF_REVISION);
    private static final ITcTypeFilter FILTER_RF_GENERIC_REVISION = new TcTypeInclusionFilter(SnecmaObjectTypes.RF_GENERIC_REVISION);

    @Override
    public BOMLineHolder explore(TcSession session, final SingleStructureServiceCaller.SingleLevelExpander expander, final BOMLineHolder genericBom) throws EmptyNomenclatureException,
            InvalidInputException, MalformedNomenclatureException {
        BOMLineHolder expandedGenericBom = expander.expand(genericBom, FILTER_RF_GENERIC_REVISION);
        BOMLineHolder rfGeneric = BOMLineHolderHelper.findRfGenericBL(expandedGenericBom);
        return expander.expand(rfGeneric, FILTER_PART_ADMIN_DESCRIPTION);
    }

}
