// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.zmlx.hg4idea.command;

import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.execution.HgCommandResult;
import org.zmlx.hg4idea.execution.HgRemoteCommandExecutor;

import java.util.ArrayList;
import java.util.List;

public class HgCloneCommand {
  private final Project project;

  private String repositoryURL;
  private String directory;

  public HgCloneCommand(Project project) {
    this.project = project;
  }

  public void setDirectory(String directory) {
    this.directory = directory;
  }

  public void setRepositoryURL(String repositoryURL) {
    this.repositoryURL = repositoryURL;
  }

  public @Nullable HgCommandResult executeInCurrentThread() {
    final List<String> arguments = new ArrayList<>(2);
    arguments.add(repositoryURL);
    arguments.add(directory);
    final HgRemoteCommandExecutor executor = new HgRemoteCommandExecutor(project, repositoryURL);
    executor.setShowOutput(true);
    return executor.executeInCurrentThread(null, "clone", arguments);
  }
}
