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

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

import javax.annotation.Nonnull;
import java.nio.file.Path;

import static java.util.Objects.requireNonNull;

public class DefaultGitRemote implements GitRemote {

    private final GitProcessBuilder builder;

    public DefaultGitRemote(GitProcessBuilder builder) {
        this.builder = builder.command("remote");
    }

    @Override
    @Nonnull
    public GitRemoteAddBuilder add(@Nonnull String name, @Nonnull Path url) {
        return add(name, requireNonNull(url, "url").toAbsolutePath().toString());
    }

    @Override
    @Nonnull
    public GitRemoteAddBuilder add(@Nonnull String name, @Nonnull String url) {
        return new DefaultGitRemoteAddBuilder(builder, name, url);
    }

    @Override
    @Nonnull
    public GitRemoteRmBuilder rm(@Nonnull String name) {
        return new DefaultGitRemoteRmBuilder(builder, name);
    }

    @Override
    @Nonnull
    public GitRemoteSetUrlBuilder setUrl(@Nonnull String name, @Nonnull Path newUrl) {
        return setUrl(name, requireNonNull(newUrl, "newUrl").toAbsolutePath().toString());
    }

    @Override
    @Nonnull
    public GitRemoteSetUrlBuilder setUrl(@Nonnull String name, @Nonnull String newUrl) {
        return new DefaultGitRemoteSetUrlBuilder(builder, name, newUrl);
    }
}
