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

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

import javax.annotation.Nonnull;

public class DefaultGitBranchDeleteBuilder
        extends AbstractGitProcessBuilder<GitBranchDeleteBuilder>
        implements GitBranchDeleteBuilder {

    private final String name;

    private boolean force;

    public DefaultGitBranchDeleteBuilder(GitProcessBuilder builder, String name) {
        super(builder);

        this.name = requireNonBlank(name, "name");
    }

    @Nonnull
    @Override
    public GitProcess<Void> build() {
        return buildWithLoggingHandler();
    }

    @Nonnull
    @Override
    public GitBranchDeleteBuilder force(boolean value) {
        force = value;

        return self();
    }

    @Override
    protected void applyArguments() {
        if (force) {
            builder.argument("-D");
        } else {
            builder.argument("-d");
        }
        builder.argument(name);
    }

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