package com.atlassian.bitbucket.internal.mirroring.mirror.client;

import com.atlassian.bitbucket.internal.mirroring.mirror.auth.OAuthAccessToken;
import com.atlassian.bitbucket.mirroring.mirror.UpstreamAccount;
import com.atlassian.bitbucket.mirroring.mirror.UpstreamServerType;
import com.atlassian.util.concurrent.Promise;

import javax.annotation.Nonnull;

/**
 * A client for interacting with a {@link UpstreamServerType#BITBUCKET_CLOUD cloud} upstream
 */
public interface CloudUpstreamClient extends InternalUpstreamClient {

    /**
     * @param repositorySlug the slug of the repository to check
     * @param publicKey the encoded public key of the user to check
     * @return the result of the authentication operation
     */
    @Nonnull
    Promise<CloudAuthenticationResult> authenticate(@Nonnull String repositorySlug, @Nonnull String publicKey);

    /**
     * Uses the provided credentials (in the form of an authorization header) to impersonate the
     * user and check for repository read permission.
     *
     * @param repositorySlug the slug of the repository to check
     * @param authorizationHeader the authorization header to use
     * @return {@code true} if the authorization header grants access to the specified repository,
     *          {@code false} otherwise
     */
    @Nonnull
    Promise<Boolean> canReadRepository(@Nonnull String repositorySlug,
                                       @Nonnull String authorizationHeader);

    /**
     * @return an OAuth access token representing the upstream addon user
     */
    @Nonnull
    Promise<OAuthAccessToken> getAccessToken();

    /**
     * @return the upstream account associated with the mirror
     */
    @Nonnull
    Promise<UpstreamAccount> getAccount();
}
