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

import com.atlassian.stash.internal.scm.git.command.AbstractGitCommandBuilder;
import com.atlassian.bitbucket.scm.git.command.GitScmCommandBuilder;
import com.atlassian.bitbucket.scm.git.command.symbolicref.GitSymbolicRefGetBuilder;

import javax.annotation.Nonnull;

/**
 * @since 1.2
 */
public class DefaultGitSymbolicRefGetBuilder
        extends AbstractGitCommandBuilder<GitSymbolicRefGetBuilder>
        implements GitSymbolicRefGetBuilder {

    private final String name;

    private boolean quiet;
    private boolean shorten;

    public DefaultGitSymbolicRefGetBuilder(GitScmCommandBuilder builder, String name) {
        super(builder);

        this.name = name;
    }

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

        return self();
    }

    @Nonnull
    @Override
    public GitSymbolicRefGetBuilder shorten(boolean value) {
        shorten = value;

        return self();
    }

    @Override
    protected void applyArguments() {
        if (quiet) {
            builder.argument("--quiet");
        }
        if (shorten) {
            builder.argument("--short");
        }
        builder.argument(name);
    }

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