package com.capgemini.reports.teamcenter.queries.saved;

import com.capgemini.framework.teamcenter.authent.TcSession;
import com.capgemini.framework.teamcenter.queries.saved.AbstractReplicatedQuery;
import com.teamcenter.soa.client.model.strong.ItemRevision;

/**
 * This class is able to look for Unit Revision objects in Teamcenter from a ChangeRequest.
 */
public class UnitFromChangeRequestQuery extends AbstractReplicatedQuery<ItemRevision, UnitFromChangeRequestQuery> {

    /**
     * Query name of Teamcenter for request in Unit objects.
     */
    private static final String QUERY_SUFFIX_UNIT_FROM_CR = "Unit_from_CR";
    private static final String PARAM_CHANGE_ID = "change_id";

    /**
     * Constructor to build a Query for Unit objects from a ChangeRequest.
     *
     * @param session the session for the connection
     */
    public UnitFromChangeRequestQuery(final TcSession session) {
        super(session, QUERY_SUFFIX_UNIT_FROM_CR);
    }

    @Override
    public UnitFromChangeRequestQuery searchID(final String alternateID) {
        this.addParam(AbstractReplicatedQuery.REPCOL_PREFIX + PARAM_CHANGE_ID, alternateID);
        return this;
    }

    @Override
    protected UnitFromChangeRequestQuery selfCast() {
        return this;
    }

}
