package com.atlassian.bitbucket.mirroring.mirror;

import com.atlassian.bitbucket.event.repository.AbstractRepositoryRefsChangedEvent;
import com.atlassian.bitbucket.repository.MinimalRef;
import com.atlassian.bitbucket.repository.RefChange;
import com.atlassian.bitbucket.repository.Repository;
import com.atlassian.event.api.AsynchronousPreferred;

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

import static java.util.Objects.requireNonNull;

/**
 * Event that is raised on the mirror server when a mirrored repository has been updated
 *
 * @since 4.3
 */
@AsynchronousPreferred
public class RepositorySynchronizedEvent extends AbstractRepositoryRefsChangedEvent {

    private final Collection<MinimalRef> failedRefs;
    private final String upstreamServerId;

    public RepositorySynchronizedEvent(@Nonnull Object source, @Nonnull Repository repository,
                                       @Nonnull Collection<RefChange> refChanges,
                                       @Nonnull Collection<MinimalRef> failedRefs,
                                       @Nonnull String upstreamServerId) {
        super(source, repository, refChanges);

        this.failedRefs = requireNonNull(failedRefs, "failedRefs");
        this.upstreamServerId = requireNonNull(upstreamServerId, "upstreamServerId");
    }

    @Nonnull
    public Collection<MinimalRef> getFailedRefs() {
        return failedRefs;
    }

    @Nonnull
    public String getUpstreamServer() {
        return upstreamServerId;
    }
}
