// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.analytics.purview.administration.generated;

import com.azure.analytics.purview.administration.AccountsClient;
import com.azure.analytics.purview.administration.AccountsClientBuilder;
import com.azure.analytics.purview.administration.CollectionsClient;
import com.azure.analytics.purview.administration.CollectionsClientBuilder;
import com.azure.analytics.purview.administration.ResourceSetRulesClient;
import com.azure.analytics.purview.administration.ResourceSetRulesClientBuilder;
import com.azure.core.credential.AccessToken;
import com.azure.core.http.HttpClient;
import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.test.TestBase;
import com.azure.core.test.TestMode;
import com.azure.core.util.Configuration;
import com.azure.identity.DefaultAzureCredentialBuilder;
import java.time.OffsetDateTime;
import reactor.core.publisher.Mono;

class PurviewAccountClientTestBase extends TestBase {
    protected AccountsClient accountsClient;

    protected CollectionsClient collectionsClient;

    protected ResourceSetRulesClient resourceSetRulesClient;

    @Override
    protected void beforeTest() {
        AccountsClientBuilder accountsClientbuilder =
                new AccountsClientBuilder()
                        .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "endpoint"))
                        .httpClient(HttpClient.createDefault())
                        .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC));
        if (getTestMode() == TestMode.PLAYBACK) {
            accountsClientbuilder
                    .httpClient(interceptorManager.getPlaybackClient())
                    .credential(request -> Mono.just(new AccessToken("this_is_a_token", OffsetDateTime.MAX)));
        } else if (getTestMode() == TestMode.RECORD) {
            accountsClientbuilder
                    .addPolicy(interceptorManager.getRecordPolicy())
                    .credential(new DefaultAzureCredentialBuilder().build());
        } else if (getTestMode() == TestMode.LIVE) {
            accountsClientbuilder.credential(new DefaultAzureCredentialBuilder().build());
        }
        accountsClient = accountsClientbuilder.buildClient();

        CollectionsClientBuilder collectionsClientbuilder =
                new CollectionsClientBuilder()
                        .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "endpoint"))
                        .httpClient(HttpClient.createDefault())
                        .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC));
        if (getTestMode() == TestMode.PLAYBACK) {
            collectionsClientbuilder
                    .httpClient(interceptorManager.getPlaybackClient())
                    .credential(request -> Mono.just(new AccessToken("this_is_a_token", OffsetDateTime.MAX)));
        } else if (getTestMode() == TestMode.RECORD) {
            collectionsClientbuilder
                    .addPolicy(interceptorManager.getRecordPolicy())
                    .credential(new DefaultAzureCredentialBuilder().build());
        } else if (getTestMode() == TestMode.LIVE) {
            collectionsClientbuilder.credential(new DefaultAzureCredentialBuilder().build());
        }
        collectionsClient = collectionsClientbuilder.buildClient();

        ResourceSetRulesClientBuilder resourceSetRulesClientbuilder =
                new ResourceSetRulesClientBuilder()
                        .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "endpoint"))
                        .httpClient(HttpClient.createDefault())
                        .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC));
        if (getTestMode() == TestMode.PLAYBACK) {
            resourceSetRulesClientbuilder
                    .httpClient(interceptorManager.getPlaybackClient())
                    .credential(request -> Mono.just(new AccessToken("this_is_a_token", OffsetDateTime.MAX)));
        } else if (getTestMode() == TestMode.RECORD) {
            resourceSetRulesClientbuilder
                    .addPolicy(interceptorManager.getRecordPolicy())
                    .credential(new DefaultAzureCredentialBuilder().build());
        } else if (getTestMode() == TestMode.LIVE) {
            resourceSetRulesClientbuilder.credential(new DefaultAzureCredentialBuilder().build());
        }
        resourceSetRulesClient = resourceSetRulesClientbuilder.buildClient();
    }
}
