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

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 DefaultGitRemoteAddBuilder
        extends AbstractGitProcessBuilder<GitRemoteAddBuilder>
        implements GitRemoteAddBuilder {

    private final String name;
    private final String url;

    public DefaultGitRemoteAddBuilder(GitProcessBuilder builder, String name, String url) {
        super(builder);

        this.name = requireNonBlank(name, "name");
        this.url = requireNonBlank(url, "url");
    }

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

    @Override
    protected void applyArguments() {
        builder.argument("add")
               .argument(name)
               .argument(url);
    }

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