// 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.MetadataPolicyClient;
import com.azure.analytics.purview.administration.MetadataPolicyClientBuilder;
import com.azure.analytics.purview.administration.MetadataRolesClient;
import com.azure.analytics.purview.administration.MetadataRolesClientBuilder;
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 PurviewMetadataClientTestBase extends TestBase {
    protected MetadataRolesClient metadataRolesClient;

    protected MetadataPolicyClient metadataPolicyClient;

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

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