package com.atlassian.bitbucket.scm.mirror;

import com.atlassian.bitbucket.i18n.KeyedMessage;
import com.atlassian.bitbucket.repository.RefChange;
import com.atlassian.bitbucket.scm.CommandFailedException;
import com.google.common.collect.ImmutableList;

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

import static java.util.Objects.requireNonNull;

/**
 * @since 4.2
 */
public class MirrorUpdateRefsCommandFailedException extends CommandFailedException {

    private static final long serialVersionUID = 1L;

    private final List<RefChange> failedChanges;

    public MirrorUpdateRefsCommandFailedException(@Nonnull KeyedMessage message, @Nonnull Collection<RefChange> failedChanges) {
        super(message);

        this.failedChanges = ImmutableList.copyOf(requireNonNull(failedChanges, "failedChanges"));
    }

    public MirrorUpdateRefsCommandFailedException(@Nonnull KeyedMessage message, @Nullable Throwable cause,
                                                  @Nonnull Iterable<RefChange> failedChanges) {
        super(message, cause);

        this.failedChanges = ImmutableList.copyOf(requireNonNull(failedChanges, "failedChanges"));
    }

    @Nonnull
    public List<RefChange> getFailedChanges() {
        return failedChanges;
    }
}
