package com.atlassian.bitbucket.branch.automerge;

import com.atlassian.bitbucket.audit.Priority;
import com.atlassian.bitbucket.event.repository.AbstractRepositoryRefsChangedEvent;
import com.atlassian.bitbucket.event.annotation.Audited;
import com.atlassian.bitbucket.repository.Branch;
import com.atlassian.bitbucket.repository.RefChange;
import com.atlassian.bitbucket.repository.Repository;
import com.google.common.collect.ImmutableList;

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

/**
 * Base event for automatic merge related events.
 * <p>
 * This event is audited in Stash with a LOW priority.
 */
@Audited(converter = AutomaticMergeEventConverter.class, priority = Priority.LOW)
public abstract class AutomaticMergeEvent extends AbstractRepositoryRefsChangedEvent {

    private final Iterable<Branch> mergePath;

    protected AutomaticMergeEvent(@Nonnull Object source, @Nonnull Repository repository,
                                  @Nonnull Collection<RefChange> actualRefChanges,
                                  @Nonnull Iterable<Branch> mergePath) {
        super(source, repository, actualRefChanges);
        this.mergePath = ImmutableList.copyOf(mergePath);
    }

    /**
     * Get the attempted merge path of the automatic merge. The merge path is ordered from the branch initiating the
     * merge cascade to the last branch in the cascade. Note: the path may, or may not have been executed fully.
     *
     * @return merge path
     */
    @Nonnull
    public Iterable<Branch> getMergePath() {
        return mergePath;
    }
}
