// 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.workflow;

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 com.azure.identity.UsernamePasswordCredentialBuilder;
import reactor.core.publisher.Mono;

class PurviewWorkflowClientTestBase extends TestBase {
    protected PurviewWorkflowClient purviewWorkflowClient;

    @Override
    protected void beforeTest() {
        PurviewWorkflowClientBuilder purviewWorkflowClientbuilder =
                new PurviewWorkflowClientBuilder()
                        .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "endpoint"))
                        .httpClient(HttpClient.createDefault())
                        .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC));
        if (getTestMode() == TestMode.PLAYBACK) {
            purviewWorkflowClientbuilder
                    .endpoint("https://REDACTED.purview.azure.com")
                    .httpClient(interceptorManager.getPlaybackClient())
                    .credential(request -> Mono.just(new AccessToken("this_is_a_token", OffsetDateTime.MAX)));
        } else if (getTestMode() == TestMode.RECORD) {
            purviewWorkflowClientbuilder
                .addPolicy(interceptorManager.getRecordPolicy())
                .credential(new UsernamePasswordCredentialBuilder()
                    .clientId(Configuration.getGlobalConfiguration().get("CLIENTID", "clientId"))
                    .tenantId(Configuration.getGlobalConfiguration().get("TENANTID", "tenantId"))
                    .username(Configuration.getGlobalConfiguration().get("USERNAME", "username"))
                    .password(Configuration.getGlobalConfiguration().get("PASSWORD", "password"))
                    .authorityHost(Configuration.getGlobalConfiguration().get("HOST", "host"))
                    .build());
        } else if (getTestMode() == TestMode.LIVE) {
            purviewWorkflowClientbuilder.credential(new DefaultAzureCredentialBuilder().build());
        }
        purviewWorkflowClient = purviewWorkflowClientbuilder.buildClient();
    }
}
