package com.atlassian.stash.internal.scm.git.command.merge;

import com.atlassian.fugue.Option;
import com.atlassian.bitbucket.scm.git.command.GitScmCommandBuilder;
import com.atlassian.bitbucket.scm.git.command.merge.GitMergeBase;
import com.atlassian.bitbucket.scm.git.command.merge.GitMergeBaseBuilder;
import com.atlassian.bitbucket.scm.git.command.merge.GitMergeBaseIndependentBuilder;

import javax.annotation.Nonnull;

/**
 * @since 1.3
 */
public class DefaultGitMergeBase implements GitMergeBase {

    private final GitScmCommandBuilder builder;

    public DefaultGitMergeBase(GitScmCommandBuilder builder) {
        this.builder = builder.command("merge-base");
    }

    @Nonnull
    @Override
    public GitMergeBaseBuilder between(@Nonnull String firstCommit, @Nonnull String secondCommit) {
        return new DefaultGitMergeBaseBuilder(builder).commits(firstCommit, secondCommit);
    }

    @Nonnull
    @Override
    public GitMergeBaseBuilder octopus() {
        return new DefaultGitMergeBaseBuilder(builder, Option.some("--octopus"));
    }

    @Nonnull
    @Override
    public GitMergeBaseIndependentBuilder independent() {
        return new DefaultGitMergeBaseIndependentBuilder(builder);
    }
}
