package com.atlassian.bitbucket.event.pull;

import com.atlassian.event.api.AsynchronousPreferred;
import com.atlassian.bitbucket.pull.PullRequest;
import com.atlassian.bitbucket.pull.PullRequestAction;
import com.atlassian.bitbucket.pull.PullRequestRole;
import com.atlassian.bitbucket.pull.PullRequestService;
import com.atlassian.bitbucket.user.ApplicationUser;
import com.google.common.collect.ImmutableSet;

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

/**
 * An event raised when one or more users have had their {@link PullRequestRole#isExplicit() explicit}
 * role in a pull request changed.
 * <p>
 * Currently the only explicit role that can be changed is the {@link PullRequestRole#REVIEWER REVIEWER} role.
 * {@link #getAddedReviewers()} and {@link #getRemovedReviewers()} allow tracking who has been
 * {@link PullRequestService#assignRole(int, long, String, PullRequestRole) assigned to} and
 * {@link PullRequestService#unassignRole(int, long, String) unassigned from} this role, respectively.
 *
 * @deprecated in 4.4 for removal in 5.0. Use {@link PullRequestReviewersUpdatedEvent} instead.
 */
@AsynchronousPreferred
@Deprecated
public class PullRequestRolesUpdatedEvent extends PullRequestEvent {

    private final Set<ApplicationUser> addedReviewers;
    private final Set<ApplicationUser> removedReviewers;

    public PullRequestRolesUpdatedEvent(@Nonnull Object source, @Nonnull PullRequest pullRequest,
                                        @Nonnull Set<ApplicationUser> added, @Nonnull Set<ApplicationUser> removed) {
        super(source, pullRequest, PullRequestAction.UPDATED);

        addedReviewers = ImmutableSet.copyOf(added);
        removedReviewers = ImmutableSet.copyOf(removed);
    }

    /**
     * @return the set of new or existing participants assigned to the reviewer role
     */
    @Nonnull
    public Set<ApplicationUser> getAddedReviewers() {
        return addedReviewers;
    }

    /**
     * @return the set of participants unassigned from the reviewer role
     */
    @Nonnull
    public Set<ApplicationUser> getRemovedReviewers() {
        return removedReviewers;
    }
}
