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

import com.atlassian.stash.internal.scm.git.command.AbstractGitCommandBuilder;
import com.atlassian.bitbucket.scm.git.command.GitCommand;
import com.atlassian.bitbucket.scm.git.command.GitScmCommandBuilder;
import com.atlassian.bitbucket.scm.git.command.prunepacked.GitPrunePackedBuilder;

import javax.annotation.Nonnull;

/**
 * @since 2.4
 */
public class DefaultGitPrunePackedBuilder
        extends AbstractGitCommandBuilder<GitPrunePackedBuilder>
        implements GitPrunePackedBuilder {

    private boolean dryRun;
    private boolean quiet;

    public DefaultGitPrunePackedBuilder(GitScmCommandBuilder builder) {
        super(builder.command("prune-packed"));
    }

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

    @Nonnull
    @Override
    public GitPrunePackedBuilder dryRun(boolean value) {
        dryRun = value;

        return self();
    }

    @Nonnull
    @Override
    public GitPrunePackedBuilder quiet(boolean value) {
        quiet = value;

        return self();
    }

    @Override
    protected void applyArguments() {
        if (dryRun) {
            builder.argument("--dry-run");
        }
        if (quiet) {
            builder.argument("--quiet");
        }
    }

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