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

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.config.GitConfigRenameSectionBuilder;

import javax.annotation.Nonnull;

/**
 * @since 2.0.4
 */
public class DefaultGitConfigRenameSectionBuilder extends AbstractGitCommandBuilder<GitConfigRenameSectionBuilder>
        implements GitConfigRenameSectionBuilder {

    private final String oldSectionName;
    private final String newSectionName;

    public DefaultGitConfigRenameSectionBuilder(GitScmCommandBuilder builder, String oldSectionName, String newSectionName) {
        super(builder);
        this.oldSectionName = checkNotBlank(oldSectionName, "oldSectionName");
        this.newSectionName = checkNotBlank(newSectionName, "newSectionName");
    }

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

    @Override
    protected void applyArguments() {
        builder.argument("--rename-section").argument(oldSectionName).argument(newSectionName);
    }

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