package com.capgemini.reports.execution.actions;

import com.capgemini.framework.teamcenter.authent.TcSession;
import com.capgemini.framework.teamcenter.exceptions.KurtException;
import com.capgemini.reports.database.javabean.DbReport;
import com.capgemini.reports.execution.AbstractExecutionReport;
import lombok.EqualsAndHashCode;

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

/** If you need to perform several {@link IPreExecutionStep}s, use this class to execute them orderly. */
@EqualsAndHashCode
public class CompositePreAction implements IPreExecutionStep {

    private static final long serialVersionUID = -7228217924123134048L;

    private final List<IPreExecutionStep> actions;

    /**
     * Creates a composite pre execution action, capable of executing several actions in series.
     * 
     * @param inputActions the actions to be carried out sequentially.
     */
    public CompositePreAction(IPreExecutionStep... inputActions) {
        this.actions = new ArrayList<>();
        Collections.addAll(this.actions, inputActions);
    }

    @Override
    public <T extends AbstractExecutionReport<T, ?>> void performPreAction(T abstractExecutionReport, DbReport dbReport, TcSession session)
            throws KurtException {
        for (IPreExecutionStep iPostExecutionStep : actions) {
            iPostExecutionStep.performPreAction(abstractExecutionReport, dbReport, session);
        }
    }
}
