package com.atlassian.stash.internal.task;

import com.google.common.collect.ImmutableList;

import javax.annotation.Nonnull;
import java.util.List;

/**
 * @see com.atlassian.stash.internal.pull.comment.CompositeCommentPostProcessor
 */
public class CompositeTaskPostProcessor implements TaskPostProcessor {

    private final List<TaskPostProcessor> postProcessors;

    public CompositeTaskPostProcessor(List<TaskPostProcessor> postProcessors) {
        this.postProcessors = ImmutableList.copyOf(postProcessors);
    }

    @Nonnull
    @Override
    public InternalTask process(InternalTask task) {
        for (TaskPostProcessor postProcessor : postProcessors) {
            task = postProcessor.process(task);
        }
        return task;
    }

    @Nonnull
    @Override
    public Iterable<InternalTask> processAll(InternalTaskContext context, Iterable<InternalTask> tasks) {
        for (TaskPostProcessor postProcessor : postProcessors) {
            tasks = postProcessor.processAll(context, tasks);
        }
        return tasks;
    }

}
