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

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 DefaultGitPrunePackedBuilder
        extends AbstractGitProcessBuilder<GitPrunePackedBuilder>
        implements GitPrunePackedBuilder {

    private boolean dryRun;
    private boolean quiet;

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

    @Nonnull
    @Override
    public GitProcess<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;
    }
}
