package com.atlassian.bitbucket.scm.git.event;

import com.atlassian.bitbucket.pull.PullRequest;
import com.atlassian.bitbucket.util.CancelState;

import javax.annotation.Nonnull;

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

/**
 * An extension for {@link GitMergeRequestedEvent} that is published when a pull request merge is attempted. This event
 * provides additional context of the {@link #getPullRequest() pull request} that is being merged.
 */
public class GitPullRequestMergeRequestedEvent extends GitMergeRequestedEvent {

    private final PullRequest pullRequest;

    public GitPullRequestMergeRequestedEvent(@Nonnull Object source, @Nonnull CancelState cancelState,
                                             @Nonnull PullRequest pullRequest, @Nonnull String mergeHash) {
        super(source, cancelState, checkNotNull(pullRequest, "pullRequest").getToRef().getRepository(),
                pullRequest.getFromRef(), pullRequest.getToRef(), mergeHash);

        this.pullRequest = pullRequest;
    }

    /**
     * Retrieves the merged {@link PullRequest pull request}.
     *
     * @return the merged pull request
     */
    @Nonnull
    public PullRequest getPullRequest() {
        return pullRequest;
    }
}
