// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { Recorder, env } from "@azure-tools/test-recorder";
import { EmailClient } from "../../../src";
const envSetupForPlayback = {
    COMMUNICATION_CONNECTION_STRING_EMAIL: "endpoint=https://someEndpoint/;accesskey=someAccessKeyw==",
    SENDER_ADDRESS: "someSender@contoso.com",
    RECIPIENT_ADDRESS: "someRecipient@domain.com",
};
const sanitizerOptions = {
    connectionStringSanitizers: [
        {
            actualConnString: env.COMMUNICATION_CONNECTION_STRING_EMAIL,
            fakeConnString: envSetupForPlayback["COMMUNICATION_CONNECTION_STRING_EMAIL"],
        },
    ],
    headerSanitizers: [
        { key: "x-ms-content-sha256", value: "Sanitized" },
        {
            key: "Operation-Location",
            value: "https://someEndpoint/emails/operations/someId?api-version=2023-03-31",
        },
    ],
    uriSanitizers: [
        {
            regex: true,
            target: `emails/operations/.*?api`,
            value: "emails/operations/someId?api",
        },
    ],
    bodySanitizers: [
        {
            regex: true,
            target: `"id"\\s?:\\s?"[^"]*"`,
            value: `"id":"someId"`,
        },
    ],
};
export async function createRecorder(context) {
    const recorder = new Recorder(context);
    await recorder.start({ envSetupForPlayback });
    await recorder.addSanitizers(sanitizerOptions, ["record", "playback"]);
    await recorder.setMatcher("CustomDefaultMatcher", {
        excludedHeaders: [
            "Accept-Language",
            "x-ms-content-sha256", // This is dependent on the current datetime
        ],
    });
    return recorder;
}
export async function createRecordedEmailClientWithConnectionString(context) {
    var _a;
    const recorder = await createRecorder(context.currentTest);
    const client = new EmailClient((_a = env.COMMUNICATION_CONNECTION_STRING_EMAIL) !== null && _a !== void 0 ? _a : "", recorder.configureClientOptions({}));
    return {
        client: client,
        recorder,
    };
}
//# sourceMappingURL=recordedClient.js.map