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

package com.azure.security.confidentialledger.certificate.generated;

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 com.azure.security.confidentialledger.certificate.ConfidentialLedgerCertificateClient;
import com.azure.security.confidentialledger.certificate.ConfidentialLedgerCertificateClientBuilder;
import java.time.OffsetDateTime;
import reactor.core.publisher.Mono;

class ConfidentialLedgerCertificateClientTestBase extends TestBase {
    protected ConfidentialLedgerCertificateClient confidentialLedgerCertificateClient;

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