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

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 DefaultGitConfigRenameSectionBuilder extends AbstractGitProcessBuilder<GitConfigRenameSectionBuilder>
        implements GitConfigRenameSectionBuilder {

    private final String oldSectionName;
    private final String newSectionName;

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

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

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

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