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

import com.atlassian.bitbucket.scm.git.command.GitScmCommandBuilder;
import com.atlassian.bitbucket.scm.git.command.remote.GitRemote;
import com.atlassian.bitbucket.scm.git.command.remote.GitRemoteAddBuilder;
import com.atlassian.bitbucket.scm.git.command.remote.GitRemoteRmBuilder;
import com.atlassian.bitbucket.scm.git.command.remote.GitRemoteSetUrlBuilder;

import javax.annotation.Nonnull;
import java.io.File;

/**
 * @since 1.2
 */
public class DefaultGitRemote implements GitRemote {

    private final GitScmCommandBuilder builder;

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

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

    @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 File newUrl) {
        return setUrl(name, newUrl.getAbsolutePath());
    }

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