package com.atlassian.stash.internal.scm;

import com.atlassian.bitbucket.commit.CommitCallback;
import com.atlassian.bitbucket.compare.CompareRequest;
import com.atlassian.bitbucket.content.ChangeCallback;
import com.atlassian.bitbucket.content.DiffContentCallback;
import com.atlassian.bitbucket.scm.Command;
import com.atlassian.bitbucket.scm.compare.CompareChangeCommandParameters;
import com.atlassian.bitbucket.scm.compare.CompareDiffCommandParameters;
import com.atlassian.bitbucket.scm.compare.PluginCompareCommandFactory;
import com.atlassian.bitbucket.scm.compare.ScmCompareCommandFactory;

import javax.annotation.Nonnull;

import static java.util.Objects.requireNonNull;

/**
 * Implements {@link ScmCompareCommandFactory} by delegating to the {@link PluginCompareCommandFactory},
 * binding a {@link CompareRequest} set during construction as the first parameter for all of its methods.
 *
 * @since 3.0
 */
public class PluginScmCompareCommandFactory implements ScmCompareCommandFactory {

    private final CompareRequest compareRequest;
    private final PluginCompareCommandFactory commandFactory;

    public PluginScmCompareCommandFactory(CompareRequest compareRequest, PluginCompareCommandFactory commandFactory) {
        this.compareRequest = requireNonNull(compareRequest, "compareRequest");
        this.commandFactory = requireNonNull(commandFactory, "commandFactory");
    }

    @Nonnull
    @Override
    public Command<Void> changes(@Nonnull CompareChangeCommandParameters parameters, @Nonnull ChangeCallback callback) {
        return commandFactory.changes(compareRequest, parameters, callback);
    }

    @Nonnull
    @Override
    public Command<Void> commits(@Nonnull CommitCallback callback) {
        return commandFactory.commits(compareRequest, callback);
    }

    @Nonnull
    @Override
    public Command<Void> diff(@Nonnull CompareDiffCommandParameters parameters, @Nonnull DiffContentCallback callback) {
        return commandFactory.diff(compareRequest, parameters, callback);
    }
}
