package com.atlassian.bitbucket.notification.pull;

import com.atlassian.bitbucket.commit.MinimalCommit;
import com.atlassian.bitbucket.pull.PullRequest;
import com.atlassian.bitbucket.user.ApplicationUser;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Date;

public class PullRequestMergedNotification extends AbstractPullRequestNotification {

    private final MinimalCommit commit;

    /**
     * @param pullRequest the pull request that was merged
     * @param timestamp   the timestamp when the merge was performed
     * @param user        the user who merged the pull request
     * @param commit      the resulting merge commit, which may be {@code null} if the pull request was
     *                    merged remotely rather than via the UI
     */
    public PullRequestMergedNotification(@Nonnull PullRequest pullRequest, @Nonnull Date timestamp,
                                         @Nullable ApplicationUser user, @Nullable MinimalCommit commit) {
        super(pullRequest, timestamp, user);

        this.commit = commit;
    }

    /**
     * @return the merge commit, which may be {@code null} if the pull request was merged remotely
     */
    @Nullable
    public MinimalCommit getCommit() {
        return commit;
    }

    @Override
    public String toString() {
        return "PullRequestMergedNotification{" + super.toString() + '}';
    }
}
