package com.atlassian.bitbucket.branch.automerge;

import com.atlassian.event.api.AsynchronousPreferred;
import com.atlassian.bitbucket.repository.Branch;
import com.atlassian.bitbucket.repository.RefChange;
import com.atlassian.bitbucket.repository.Repository;

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

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Raised when an automatic merge cascade did not proceed to the end of the merge path, which may happen due to multiple
 * reasons.
 */
@AsynchronousPreferred
public class AutomaticMergeStoppedEvent extends AutomaticMergeEvent {

    private final AutomaticMergeStopReason reason;

    public AutomaticMergeStoppedEvent(@Nonnull Object source, @Nonnull Repository repository,
                                      @Nonnull Collection<RefChange> actualRefChanges,
                                      @Nonnull Iterable<Branch> mergePath,
                                      @Nonnull AutomaticMergeStopReason reason) {
        super(source, repository, actualRefChanges, mergePath);
        this.reason = checkNotNull(reason, "reason");
    }

    @Nonnull
    public AutomaticMergeStopReason getReason() {
        return reason;
    }
}
