package com.atlassian.bitbucket.internal.mirroring.mirror.auth.ssh;

import com.atlassian.bitbucket.repository.Repository;
import com.atlassian.bitbucket.scm.ssh.ExitCodeCallback;
import com.atlassian.bitbucket.scm.ssh.SshScmRequest;

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

/**
 * A noop scm request, which exists immediately when run.
 */
public class NoOpSshScmRequest implements SshScmRequest {

    private final ExitCodeCallback exitCodeCallback;
    private final Repository repository;

    NoOpSshScmRequest(ExitCodeCallback exitCodeCallback, Repository repository) {
        this.exitCodeCallback = exitCodeCallback;
        this.repository = repository;
    }

    @Nonnull
    @Override
    public Repository getRepository() {
        return repository;
    }

    @Override
    public void handleRequest() throws IOException {
        exitCodeCallback.onExit(1);
    }

    @Override
    public void cancel() {
        // No-op. This command is not long running.
    }

    @Override
    public boolean isWrite() {
        return false;
    }

    @Override
    public void sendError(@Nonnull String summary, @Nonnull String detailMessage) throws IOException {
        // No-op.
    }
}
