/*
 * Copyright (c) Microsoft Corporation.
 * Licensed under the MIT License.
 *
 * Code generated by Microsoft (R) AutoRest Code Generator.
 * Changes may cause incorrect behavior and will be lost if the code is regenerated.
 */
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers";
import * as Parameters from "../models/parameters";
import { LroEngine } from "@azure/core-lro";
import { LroImpl } from "../lroImpl";
/** Class containing Email operations. */
export class EmailImpl {
    /**
     * Initialize a new instance of the class Email class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * Gets the status of the email send operation.
     * @param operationId ID of the long running operation (GUID) returned from a previous call to send
     *                    email
     * @param options The options parameters.
     */
    getSendResult(operationId, options) {
        return this.client.sendOperationRequest({ operationId, options }, getSendResultOperationSpec);
    }
    /**
     * Queues an email message to be sent to one or more recipients
     * @param message Message payload for sending an email
     * @param options The options parameters.
     */
    async beginSend(message, options) {
        const directSendOperation = async (args, spec) => {
            return this.client.sendOperationRequest(args, spec);
        };
        const sendOperation = async (args, spec) => {
            var _a;
            let currentRawResponse = undefined;
            const providedCallback = (_a = args.options) === null || _a === void 0 ? void 0 : _a.onResponse;
            const callback = (rawResponse, flatResponse) => {
                currentRawResponse = rawResponse;
                providedCallback === null || providedCallback === void 0 ? void 0 : providedCallback(rawResponse, flatResponse);
            };
            const updatedArgs = Object.assign(Object.assign({}, args), { options: Object.assign(Object.assign({}, args.options), { onResponse: callback }) });
            const flatResponse = await directSendOperation(updatedArgs, spec);
            return {
                flatResponse,
                rawResponse: {
                    statusCode: currentRawResponse.status,
                    body: currentRawResponse.parsedBody,
                    headers: currentRawResponse.headers.toJSON()
                }
            };
        };
        const lro = new LroImpl(sendOperation, { message, options }, sendOperationSpec);
        const poller = new LroEngine(lro, {
            resumeFrom: options === null || options === void 0 ? void 0 : options.resumeFrom,
            intervalInMs: options === null || options === void 0 ? void 0 : options.updateIntervalInMs,
            lroResourceLocationConfig: "azure-async-operation"
        });
        await poller.poll();
        return poller;
    }
    /**
     * Queues an email message to be sent to one or more recipients
     * @param message Message payload for sending an email
     * @param options The options parameters.
     */
    async beginSendAndWait(message, options) {
        const poller = await this.beginSend(message, options);
        return poller.pollUntilDone();
    }
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const getSendResultOperationSpec = {
    path: "/emails/operations/{operationId}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.EmailSendResult,
            headersMapper: Mappers.EmailGetSendResultHeaders
        },
        default: {
            bodyMapper: Mappers.ErrorResponse,
            headersMapper: Mappers.EmailGetSendResultExceptionHeaders
        }
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [Parameters.endpoint, Parameters.operationId],
    headerParameters: [Parameters.accept],
    serializer
};
const sendOperationSpec = {
    path: "/emails:send",
    httpMethod: "POST",
    responses: {
        200: {
            bodyMapper: Mappers.EmailSendResult,
            headersMapper: Mappers.EmailSendHeaders
        },
        201: {
            bodyMapper: Mappers.EmailSendResult,
            headersMapper: Mappers.EmailSendHeaders
        },
        202: {
            bodyMapper: Mappers.EmailSendResult,
            headersMapper: Mappers.EmailSendHeaders
        },
        204: {
            bodyMapper: Mappers.EmailSendResult,
            headersMapper: Mappers.EmailSendHeaders
        },
        default: {
            bodyMapper: Mappers.ErrorResponse,
            headersMapper: Mappers.EmailSendExceptionHeaders
        }
    },
    requestBody: Parameters.message,
    queryParameters: [Parameters.apiVersion],
    urlParameters: [Parameters.endpoint],
    headerParameters: [
        Parameters.accept,
        Parameters.contentType,
        Parameters.operationId1,
        Parameters.clientRequestId
    ],
    mediaType: "json",
    serializer
};
//# sourceMappingURL=email.js.map