package com.atlassian.bitbucket.mesh.git.builder.merge;

import com.atlassian.bitbucket.mesh.git.builder.GitProcessBuilder;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class DefaultGitMergeBaseBuilder
        extends AbstractGitMergeBaseBuilder<GitMergeBaseBuilder>
        implements GitMergeBaseBuilder {

    private final String mode;

    private boolean all;

    public DefaultGitMergeBaseBuilder(@Nonnull GitProcessBuilder builder) {
        this(builder, null);
    }

    public DefaultGitMergeBaseBuilder(@Nonnull GitProcessBuilder builder, @Nullable String mode) {
        super(builder);

        this.mode = mode;
    }

    @Nonnull
    @Override
    public GitMergeBaseBuilder all(boolean value) {
        all = value;

        return self();
    }

    @Override
    protected void applyModeArguments() {
        if (all) {
            builder.argument("--all");
        }
        if (mode != null) {
            builder.argument(mode);
        }
    }

    @Nonnull
    @Override
    protected GitMergeBaseBuilder self() {
        return this;
    }
}
