// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.aad.msal4j;

import java.util.Set;

/**
 * Used to define the basic set of methods that all Brokers must implement
 *
 * All methods are so they can be referenced by MSAL Java without an implementation, and by default simply throw an
 * exception saying that a broker implementation is missing
 */
public interface IBroker {

    /**
     * Called when the 'useBroker' flag is first set, and will perform any initialization needed to make the broker available for future calls
     *
     * Will also detect dependency or accessibility errors with the Broker package, allowing an exception to provide the error to the app developer
     * before any actual calls to a broker are made
     */
    default void initializeBroker(){
        throw new MsalClientException("Broker implementation missing", AuthenticationErrorCode.MISSING_BROKER);
    }

    /**
     * Acquire a token silently, i.e. without direct user interaction
     *
     * This may be accomplished by returning tokens from a token cache, using cached refresh tokens to get new tokens,
     * or via any authentication flow where a user is not prompted to enter credentials
     *
     * @param requestParameters MsalRequest object which contains everything needed for the broker implementation to make a request
     * @return IBroker implementations will return an AuthenticationResult object
     */
    default IAuthenticationResult acquireToken(PublicClientApplication application, SilentParameters requestParameters) {
        throw new MsalClientException("Broker implementation missing", AuthenticationErrorCode.MISSING_BROKER);
    }

    /**
     * Acquire a token silently, i.e. without direct user interaction, using a refresh token
     *
     * This requires the broker implementation to cache the refresh tokens, either in its own cache or by populating MSAL Java's cache,
     * or otherwise have some way of retrieving refresh tokens cached somewhere else
     *
     * @param requestParameters MsalRequest object which contains everything needed for the broker implementation to make a request
     * @return IBroker implementations will return an AuthenticationResult object
     */
    default IAuthenticationResult acquireToken(PublicClientApplication application, RefreshTokenParameters requestParameters) {
        throw new MsalClientException("Broker implementation missing", AuthenticationErrorCode.MISSING_BROKER);
    }

    /**
     * Acquire a token interactively, by prompting users to enter their credentials in some way
     *
     * @param requestParameters MsalRequest object which contains everything needed for the broker implementation to make a request
     * @return IBroker implementations will return an AuthenticationResult object
     */
    default IAuthenticationResult acquireToken(PublicClientApplication application, InteractiveRequestParameters requestParameters) {
        throw new MsalClientException("Broker implementation missing", AuthenticationErrorCode.MISSING_BROKER);
    }

    /**
     * Acquire a token silently, i.e. without direct user interaction, using username/password authentication
     *
     * @param requestParameters MsalRequest object which contains everything needed for the broker implementation to make a request
     * @return IBroker implementations will return an AuthenticationResult object
     */
    default IAuthenticationResult acquireToken(PublicClientApplication application, UserNamePasswordParameters requestParameters) {
        throw new MsalClientException("Broker implementation missing", AuthenticationErrorCode.MISSING_BROKER);
    }

    /**
     * Retrieve an account information from the broker based on an account ID
     *
     * @return IAccount implementations will return an Account object
     */
    default Account getAccount(String id) {
        throw new MsalClientException("Broker implementation missing", AuthenticationErrorCode.MISSING_BROKER);
    }

    //TODO: Not needed? ClientApplication has getAccounts(), but that would rely on us caching the accounts, which MSALRuntime also caches
    default Set<Account> getAccounts() {
        throw new MsalClientException("Broker implementation missing", AuthenticationErrorCode.MISSING_BROKER);
    }
}
@@ -146,16 +146,63 @@
 til.Set;
+%0Aimport java.util.concurrent.CompletableFuture;
 %0A%0A/**%0A *
@@ -1773,813 +1773,8 @@
  %7D%0A%0A
-    /**%0A     * Acquire a token silently, i.e. without direct user interaction, using a refresh token%0A     *%0A     * This requires the broker implementation to cache the refresh tokens, either in its own cache or by populating MSAL Java's cache,%0A     * or otherwise have some way of retrieving refresh tokens cached somewhere else%0A     *%0A     * @param requestParameters MsalRequest object which contains everything needed for the broker implementation to make a request%0A     * @return IBroker implementations will return an AuthenticationResult object%0A     */%0A    default IAuthenticationResult acquireToken(PublicClientApplication application, RefreshTokenParameters requestParameters) %7B%0A        throw new MsalClientException(%22Broker implementation missing%22, AuthenticationErrorCode.MISSING_BROKER);%0A    %7D%0A%0A
     
@@ -2961,514 +2961,64 @@
     
-/**%0A     * Retrieve an account information from the broker based on an account ID%0A     *%0A     * @return IAccount implementations will return an Account object%0A     */%0A    default Account getAccount(String id) %7B%0A        throw new MsalClientException(%22Broker implementation missing%22, AuthenticationErrorCode.MISSING_BROKER);%0A    %7D%0A%0A    //TODO: Not needed? ClientApplication has getAccounts(), but that would rely on us caching the accounts, which MSALRuntime also caches%0A    default Set%3C
+default CompletableFuture removeAccount(I
 Account
-%3E getA
+ a
 ccount
-s(
 ) %7B%0A

address PR comments