package com.atlassian.bitbucket.repository.ref.restriction;

import com.atlassian.bitbucket.audit.Channels;
import com.atlassian.bitbucket.audit.Priority;
import com.atlassian.bitbucket.event.repository.RepositoryEvent;
import com.atlassian.bitbucket.event.annotation.Audited;
import com.atlassian.bitbucket.event.annotation.TransactionAware;
import com.atlassian.bitbucket.repository.Repository;
import com.atlassian.bitbucket.user.ApplicationUser;
import com.google.common.collect.ImmutableList;

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

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

/**
 * The abstract base for all events related to {@link RefRestriction RefRestrictions}.
 */
@TransactionAware
@Audited(converter = RefRestrictionEventConverter.class, channels = {Channels.REPOSITORY_UI}, priority = Priority.HIGH)
public abstract class RefRestrictionEvent extends RepositoryEvent {

    private final List<String> affectedGroups;
    private final List<ApplicationUser> affectedUsers;
    private final RefRestriction restriction;

    public RefRestrictionEvent(@Nonnull Object source,
                               @Nonnull Repository repository,
                               @Nonnull RefRestriction restriction,
                               @Nonnull Collection<ApplicationUser> affectedUsers,
                               @Nonnull Collection<String> affectedGroups) {
        super(source, repository);

        this.affectedGroups = ImmutableList.copyOf(checkNotNull(affectedGroups, "affectedGroups"));
        this.affectedUsers = ImmutableList.copyOf(checkNotNull(affectedUsers, "affectedUsers"));
        this.restriction = checkNotNull(restriction, "restriction");
    }

    @Nonnull
    public List<String> getAffectedGroups() {
        return affectedGroups;
    }

    @Nonnull
    public List<ApplicationUser> getAffectedUsers() {
        return affectedUsers;
    }

    @Nonnull
    public RefRestriction getRestriction() {
        return restriction;
    }
}
