package com.atlassian.bitbucket.notification.pull;

import com.atlassian.bitbucket.notification.AbstractNotification;
import com.atlassian.bitbucket.pull.PullRequest;
import com.atlassian.bitbucket.user.ApplicationUser;

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

import static java.util.Objects.requireNonNull;

public abstract class AbstractPullRequestNotification extends AbstractNotification implements PullRequestNotification {

    private final PullRequest pullRequest;

    public AbstractPullRequestNotification(@Nonnull PullRequest pullRequest, @Nonnull Date timestamp,
                                           @Nullable ApplicationUser user) {
        super(user, timestamp);

        this.pullRequest = requireNonNull(pullRequest, "pullRequest");
    }

    @Nonnull
    @Override
    public PullRequest getPullRequest() {
        return pullRequest;
    }

    @Override
    public String toString() {
        return super.toString() + ", pullRequest=" + pullRequest.getToRef().getRepository().getSlug() +
                ":" + pullRequest.getId();
    }
}
