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

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

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

public class DefaultGitPruneBuilder extends AbstractGitProcessBuilder<GitPruneBuilder> implements GitPruneBuilder {

    private boolean dryRun;
    private String expire;
    private boolean verbose;

    public DefaultGitPruneBuilder(GitProcessBuilder builder) {
        super(builder.command("prune"));
    }

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

        return self();
    }

    @Nonnull
    @Override
    public GitPruneBuilder expire(@Nullable String value) {
        expire = value;

        return self();
    }

    @Nonnull
    @Override
    public GitPruneBuilder verbose(boolean value) {
        verbose = value;

        return self();
    }

    @Override
    protected void applyArguments() {
        if (dryRun) {
            builder.argument("--dry-run");
        }
        if (verbose) {
            builder.argument("--verbose");
        }
        if (expire != null) {
            builder.argument("--expire").argument(expire);
        }
        builder.argument("--");
    }

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