package com.atlassian.stash.internal.scm;

import com.atlassian.bitbucket.repository.Repository;
import com.atlassian.bitbucket.repository.Branch;
import com.atlassian.bitbucket.repository.Tag;
import com.atlassian.bitbucket.scm.Command;
import com.atlassian.bitbucket.scm.ref.CreateBranchCommandParameters;
import com.atlassian.bitbucket.scm.ref.CreateTagCommandParameters;
import com.atlassian.bitbucket.scm.ref.PluginRefCommandFactory;
import com.atlassian.bitbucket.scm.ref.ScmRefCommandFactory;

import javax.annotation.Nonnull;

/**
 * Implements {@link ScmRefCommandFactory} by delegating to the
 * {@link PluginRefCommandFactory}, binding {@link Repository}
 * set during construction as the first parameter for all of its methods.
 *
 * @since 3.5
 */
public class PluginScmRefCommandFactory implements ScmRefCommandFactory {

    private final Repository repository;
    private final PluginRefCommandFactory commandFactory;

    public PluginScmRefCommandFactory(Repository repository, PluginRefCommandFactory commandFactory) {
        this.repository = repository;
        this.commandFactory = commandFactory;
    }

    @Nonnull
    @Override
    public Command<Branch> createBranch(@Nonnull CreateBranchCommandParameters parameters) {
        return commandFactory.createBranch(repository, parameters);
    }

    @Nonnull
    @Override
    public Command<Tag> createTag(@Nonnull CreateTagCommandParameters parameters) {
        return commandFactory.createTag(repository, parameters);
    }
}
