/*
 * 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 { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging";
import { setContinuationToken } from "../pagingHelper";
import { AppServiceCertificateOrders } from "../operationsInterfaces";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers";
import * as Parameters from "../models/parameters";
import { WebSiteManagementClient } from "../webSiteManagementClient";
import {
  SimplePollerLike,
  OperationState,
  createHttpPoller
} from "@azure/core-lro";
import { createLroSpec } from "../lroImpl";
import {
  AppServiceCertificateOrder,
  AppServiceCertificateOrdersListNextOptionalParams,
  AppServiceCertificateOrdersListOptionalParams,
  AppServiceCertificateOrdersListResponse,
  AppServiceCertificateOrdersListByResourceGroupNextOptionalParams,
  AppServiceCertificateOrdersListByResourceGroupOptionalParams,
  AppServiceCertificateOrdersListByResourceGroupResponse,
  AppServiceCertificateResource,
  AppServiceCertificateOrdersListCertificatesNextOptionalParams,
  AppServiceCertificateOrdersListCertificatesOptionalParams,
  AppServiceCertificateOrdersListCertificatesResponse,
  AppServiceCertificateOrdersValidatePurchaseInformationOptionalParams,
  AppServiceCertificateOrdersGetOptionalParams,
  AppServiceCertificateOrdersGetResponse,
  AppServiceCertificateOrdersCreateOrUpdateOptionalParams,
  AppServiceCertificateOrdersCreateOrUpdateResponse,
  AppServiceCertificateOrdersDeleteOptionalParams,
  AppServiceCertificateOrderPatchResource,
  AppServiceCertificateOrdersUpdateOptionalParams,
  AppServiceCertificateOrdersUpdateResponse,
  AppServiceCertificateOrdersGetCertificateOptionalParams,
  AppServiceCertificateOrdersGetCertificateResponse,
  AppServiceCertificateOrdersCreateOrUpdateCertificateOptionalParams,
  AppServiceCertificateOrdersCreateOrUpdateCertificateResponse,
  AppServiceCertificateOrdersDeleteCertificateOptionalParams,
  AppServiceCertificatePatchResource,
  AppServiceCertificateOrdersUpdateCertificateOptionalParams,
  AppServiceCertificateOrdersUpdateCertificateResponse,
  ReissueCertificateOrderRequest,
  AppServiceCertificateOrdersReissueOptionalParams,
  RenewCertificateOrderRequest,
  AppServiceCertificateOrdersRenewOptionalParams,
  AppServiceCertificateOrdersResendEmailOptionalParams,
  NameIdentifier,
  AppServiceCertificateOrdersResendRequestEmailsOptionalParams,
  SiteSealRequest,
  AppServiceCertificateOrdersRetrieveSiteSealOptionalParams,
  AppServiceCertificateOrdersRetrieveSiteSealResponse,
  AppServiceCertificateOrdersVerifyDomainOwnershipOptionalParams,
  AppServiceCertificateOrdersRetrieveCertificateActionsOptionalParams,
  AppServiceCertificateOrdersRetrieveCertificateActionsResponse,
  AppServiceCertificateOrdersRetrieveCertificateEmailHistoryOptionalParams,
  AppServiceCertificateOrdersRetrieveCertificateEmailHistoryResponse,
  AppServiceCertificateOrdersListNextResponse,
  AppServiceCertificateOrdersListByResourceGroupNextResponse,
  AppServiceCertificateOrdersListCertificatesNextResponse
} from "../models";

/// <reference lib="esnext.asynciterable" />
/** Class containing AppServiceCertificateOrders operations. */
export class AppServiceCertificateOrdersImpl
  implements AppServiceCertificateOrders {
  private readonly client: WebSiteManagementClient;

  /**
   * Initialize a new instance of the class AppServiceCertificateOrders class.
   * @param client Reference to the service client
   */
  constructor(client: WebSiteManagementClient) {
    this.client = client;
  }

  /**
   * Description for List all certificate orders in a subscription.
   * @param options The options parameters.
   */
  public list(
    options?: AppServiceCertificateOrdersListOptionalParams
  ): PagedAsyncIterableIterator<AppServiceCertificateOrder> {
    const iter = this.listPagingAll(options);
    return {
      next() {
        return iter.next();
      },
      [Symbol.asyncIterator]() {
        return this;
      },
      byPage: (settings?: PageSettings) => {
        if (settings?.maxPageSize) {
          throw new Error("maxPageSize is not supported by this operation.");
        }
        return this.listPagingPage(options, settings);
      }
    };
  }

  private async *listPagingPage(
    options?: AppServiceCertificateOrdersListOptionalParams,
    settings?: PageSettings
  ): AsyncIterableIterator<AppServiceCertificateOrder[]> {
    let result: AppServiceCertificateOrdersListResponse;
    let continuationToken = settings?.continuationToken;
    if (!continuationToken) {
      result = await this._list(options);
      let page = result.value || [];
      continuationToken = result.nextLink;
      setContinuationToken(page, continuationToken);
      yield page;
    }
    while (continuationToken) {
      result = await this._listNext(continuationToken, options);
      continuationToken = result.nextLink;
      let page = result.value || [];
      setContinuationToken(page, continuationToken);
      yield page;
    }
  }

  private async *listPagingAll(
    options?: AppServiceCertificateOrdersListOptionalParams
  ): AsyncIterableIterator<AppServiceCertificateOrder> {
    for await (const page of this.listPagingPage(options)) {
      yield* page;
    }
  }

  /**
   * Description for Get certificate orders in a resource group.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param options The options parameters.
   */
  public listByResourceGroup(
    resourceGroupName: string,
    options?: AppServiceCertificateOrdersListByResourceGroupOptionalParams
  ): PagedAsyncIterableIterator<AppServiceCertificateOrder> {
    const iter = this.listByResourceGroupPagingAll(resourceGroupName, options);
    return {
      next() {
        return iter.next();
      },
      [Symbol.asyncIterator]() {
        return this;
      },
      byPage: (settings?: PageSettings) => {
        if (settings?.maxPageSize) {
          throw new Error("maxPageSize is not supported by this operation.");
        }
        return this.listByResourceGroupPagingPage(
          resourceGroupName,
          options,
          settings
        );
      }
    };
  }

  private async *listByResourceGroupPagingPage(
    resourceGroupName: string,
    options?: AppServiceCertificateOrdersListByResourceGroupOptionalParams,
    settings?: PageSettings
  ): AsyncIterableIterator<AppServiceCertificateOrder[]> {
    let result: AppServiceCertificateOrdersListByResourceGroupResponse;
    let continuationToken = settings?.continuationToken;
    if (!continuationToken) {
      result = await this._listByResourceGroup(resourceGroupName, options);
      let page = result.value || [];
      continuationToken = result.nextLink;
      setContinuationToken(page, continuationToken);
      yield page;
    }
    while (continuationToken) {
      result = await this._listByResourceGroupNext(
        resourceGroupName,
        continuationToken,
        options
      );
      continuationToken = result.nextLink;
      let page = result.value || [];
      setContinuationToken(page, continuationToken);
      yield page;
    }
  }

  private async *listByResourceGroupPagingAll(
    resourceGroupName: string,
    options?: AppServiceCertificateOrdersListByResourceGroupOptionalParams
  ): AsyncIterableIterator<AppServiceCertificateOrder> {
    for await (const page of this.listByResourceGroupPagingPage(
      resourceGroupName,
      options
    )) {
      yield* page;
    }
  }

  /**
   * Description for List all certificates associated with a certificate order.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param certificateOrderName Name of the certificate order.
   * @param options The options parameters.
   */
  public listCertificates(
    resourceGroupName: string,
    certificateOrderName: string,
    options?: AppServiceCertificateOrdersListCertificatesOptionalParams
  ): PagedAsyncIterableIterator<AppServiceCertificateResource> {
    const iter = this.listCertificatesPagingAll(
      resourceGroupName,
      certificateOrderName,
      options
    );
    return {
      next() {
        return iter.next();
      },
      [Symbol.asyncIterator]() {
        return this;
      },
      byPage: (settings?: PageSettings) => {
        if (settings?.maxPageSize) {
          throw new Error("maxPageSize is not supported by this operation.");
        }
        return this.listCertificatesPagingPage(
          resourceGroupName,
          certificateOrderName,
          options,
          settings
        );
      }
    };
  }

  private async *listCertificatesPagingPage(
    resourceGroupName: string,
    certificateOrderName: string,
    options?: AppServiceCertificateOrdersListCertificatesOptionalParams,
    settings?: PageSettings
  ): AsyncIterableIterator<AppServiceCertificateResource[]> {
    let result: AppServiceCertificateOrdersListCertificatesResponse;
    let continuationToken = settings?.continuationToken;
    if (!continuationToken) {
      result = await this._listCertificates(
        resourceGroupName,
        certificateOrderName,
        options
      );
      let page = result.value || [];
      continuationToken = result.nextLink;
      setContinuationToken(page, continuationToken);
      yield page;
    }
    while (continuationToken) {
      result = await this._listCertificatesNext(
        resourceGroupName,
        certificateOrderName,
        continuationToken,
        options
      );
      continuationToken = result.nextLink;
      let page = result.value || [];
      setContinuationToken(page, continuationToken);
      yield page;
    }
  }

  private async *listCertificatesPagingAll(
    resourceGroupName: string,
    certificateOrderName: string,
    options?: AppServiceCertificateOrdersListCertificatesOptionalParams
  ): AsyncIterableIterator<AppServiceCertificateResource> {
    for await (const page of this.listCertificatesPagingPage(
      resourceGroupName,
      certificateOrderName,
      options
    )) {
      yield* page;
    }
  }

  /**
   * Description for List all certificate orders in a subscription.
   * @param options The options parameters.
   */
  private _list(
    options?: AppServiceCertificateOrdersListOptionalParams
  ): Promise<AppServiceCertificateOrdersListResponse> {
    return this.client.sendOperationRequest({ options }, listOperationSpec);
  }

  /**
   * Description for Validate information for a certificate order.
   * @param appServiceCertificateOrder Information for a certificate order.
   * @param options The options parameters.
   */
  validatePurchaseInformation(
    appServiceCertificateOrder: AppServiceCertificateOrder,
    options?: AppServiceCertificateOrdersValidatePurchaseInformationOptionalParams
  ): Promise<void> {
    return this.client.sendOperationRequest(
      { appServiceCertificateOrder, options },
      validatePurchaseInformationOperationSpec
    );
  }

  /**
   * Description for Get certificate orders in a resource group.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param options The options parameters.
   */
  private _listByResourceGroup(
    resourceGroupName: string,
    options?: AppServiceCertificateOrdersListByResourceGroupOptionalParams
  ): Promise<AppServiceCertificateOrdersListByResourceGroupResponse> {
    return this.client.sendOperationRequest(
      { resourceGroupName, options },
      listByResourceGroupOperationSpec
    );
  }

  /**
   * Description for Get a certificate order.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param certificateOrderName Name of the certificate order..
   * @param options The options parameters.
   */
  get(
    resourceGroupName: string,
    certificateOrderName: string,
    options?: AppServiceCertificateOrdersGetOptionalParams
  ): Promise<AppServiceCertificateOrdersGetResponse> {
    return this.client.sendOperationRequest(
      { resourceGroupName, certificateOrderName, options },
      getOperationSpec
    );
  }

  /**
   * Description for Create or update a certificate purchase order.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param certificateOrderName Name of the certificate order.
   * @param certificateDistinguishedName Distinguished name to use for the certificate order.
   * @param options The options parameters.
   */
  async beginCreateOrUpdate(
    resourceGroupName: string,
    certificateOrderName: string,
    certificateDistinguishedName: AppServiceCertificateOrder,
    options?: AppServiceCertificateOrdersCreateOrUpdateOptionalParams
  ): Promise<
    SimplePollerLike<
      OperationState<AppServiceCertificateOrdersCreateOrUpdateResponse>,
      AppServiceCertificateOrdersCreateOrUpdateResponse
    >
  > {
    const directSendOperation = async (
      args: coreClient.OperationArguments,
      spec: coreClient.OperationSpec
    ): Promise<AppServiceCertificateOrdersCreateOrUpdateResponse> => {
      return this.client.sendOperationRequest(args, spec);
    };
    const sendOperationFn = async (
      args: coreClient.OperationArguments,
      spec: coreClient.OperationSpec
    ) => {
      let currentRawResponse:
        | coreClient.FullOperationResponse
        | undefined = undefined;
      const providedCallback = args.options?.onResponse;
      const callback: coreClient.RawResponseCallback = (
        rawResponse: coreClient.FullOperationResponse,
        flatResponse: unknown
      ) => {
        currentRawResponse = rawResponse;
        providedCallback?.(rawResponse, flatResponse);
      };
      const updatedArgs = {
        ...args,
        options: {
          ...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 = createLroSpec({
      sendOperationFn,
      args: {
        resourceGroupName,
        certificateOrderName,
        certificateDistinguishedName,
        options
      },
      spec: createOrUpdateOperationSpec
    });
    const poller = await createHttpPoller<
      AppServiceCertificateOrdersCreateOrUpdateResponse,
      OperationState<AppServiceCertificateOrdersCreateOrUpdateResponse>
    >(lro, {
      restoreFrom: options?.resumeFrom,
      intervalInMs: options?.updateIntervalInMs
    });
    await poller.poll();
    return poller;
  }

  /**
   * Description for Create or update a certificate purchase order.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param certificateOrderName Name of the certificate order.
   * @param certificateDistinguishedName Distinguished name to use for the certificate order.
   * @param options The options parameters.
   */
  async beginCreateOrUpdateAndWait(
    resourceGroupName: string,
    certificateOrderName: string,
    certificateDistinguishedName: AppServiceCertificateOrder,
    options?: AppServiceCertificateOrdersCreateOrUpdateOptionalParams
  ): Promise<AppServiceCertificateOrdersCreateOrUpdateResponse> {
    const poller = await this.beginCreateOrUpdate(
      resourceGroupName,
      certificateOrderName,
      certificateDistinguishedName,
      options
    );
    return poller.pollUntilDone();
  }

  /**
   * Description for Delete an existing certificate order.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param certificateOrderName Name of the certificate order.
   * @param options The options parameters.
   */
  delete(
    resourceGroupName: string,
    certificateOrderName: string,
    options?: AppServiceCertificateOrdersDeleteOptionalParams
  ): Promise<void> {
    return this.client.sendOperationRequest(
      { resourceGroupName, certificateOrderName, options },
      deleteOperationSpec
    );
  }

  /**
   * Description for Create or update a certificate purchase order.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param certificateOrderName Name of the certificate order.
   * @param certificateDistinguishedName Distinguished name to use for the certificate order.
   * @param options The options parameters.
   */
  update(
    resourceGroupName: string,
    certificateOrderName: string,
    certificateDistinguishedName: AppServiceCertificateOrderPatchResource,
    options?: AppServiceCertificateOrdersUpdateOptionalParams
  ): Promise<AppServiceCertificateOrdersUpdateResponse> {
    return this.client.sendOperationRequest(
      {
        resourceGroupName,
        certificateOrderName,
        certificateDistinguishedName,
        options
      },
      updateOperationSpec
    );
  }

  /**
   * Description for List all certificates associated with a certificate order.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param certificateOrderName Name of the certificate order.
   * @param options The options parameters.
   */
  private _listCertificates(
    resourceGroupName: string,
    certificateOrderName: string,
    options?: AppServiceCertificateOrdersListCertificatesOptionalParams
  ): Promise<AppServiceCertificateOrdersListCertificatesResponse> {
    return this.client.sendOperationRequest(
      { resourceGroupName, certificateOrderName, options },
      listCertificatesOperationSpec
    );
  }

  /**
   * Description for Get the certificate associated with a certificate order.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param certificateOrderName Name of the certificate order.
   * @param name Name of the certificate.
   * @param options The options parameters.
   */
  getCertificate(
    resourceGroupName: string,
    certificateOrderName: string,
    name: string,
    options?: AppServiceCertificateOrdersGetCertificateOptionalParams
  ): Promise<AppServiceCertificateOrdersGetCertificateResponse> {
    return this.client.sendOperationRequest(
      { resourceGroupName, certificateOrderName, name, options },
      getCertificateOperationSpec
    );
  }

  /**
   * Description for Creates or updates a certificate and associates with key vault secret.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param certificateOrderName Name of the certificate order.
   * @param name Name of the certificate.
   * @param keyVaultCertificate Key vault certificate resource Id.
   * @param options The options parameters.
   */
  async beginCreateOrUpdateCertificate(
    resourceGroupName: string,
    certificateOrderName: string,
    name: string,
    keyVaultCertificate: AppServiceCertificateResource,
    options?: AppServiceCertificateOrdersCreateOrUpdateCertificateOptionalParams
  ): Promise<
    SimplePollerLike<
      OperationState<
        AppServiceCertificateOrdersCreateOrUpdateCertificateResponse
      >,
      AppServiceCertificateOrdersCreateOrUpdateCertificateResponse
    >
  > {
    const directSendOperation = async (
      args: coreClient.OperationArguments,
      spec: coreClient.OperationSpec
    ): Promise<AppServiceCertificateOrdersCreateOrUpdateCertificateResponse> => {
      return this.client.sendOperationRequest(args, spec);
    };
    const sendOperationFn = async (
      args: coreClient.OperationArguments,
      spec: coreClient.OperationSpec
    ) => {
      let currentRawResponse:
        | coreClient.FullOperationResponse
        | undefined = undefined;
      const providedCallback = args.options?.onResponse;
      const callback: coreClient.RawResponseCallback = (
        rawResponse: coreClient.FullOperationResponse,
        flatResponse: unknown
      ) => {
        currentRawResponse = rawResponse;
        providedCallback?.(rawResponse, flatResponse);
      };
      const updatedArgs = {
        ...args,
        options: {
          ...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 = createLroSpec({
      sendOperationFn,
      args: {
        resourceGroupName,
        certificateOrderName,
        name,
        keyVaultCertificate,
        options
      },
      spec: createOrUpdateCertificateOperationSpec
    });
    const poller = await createHttpPoller<
      AppServiceCertificateOrdersCreateOrUpdateCertificateResponse,
      OperationState<
        AppServiceCertificateOrdersCreateOrUpdateCertificateResponse
      >
    >(lro, {
      restoreFrom: options?.resumeFrom,
      intervalInMs: options?.updateIntervalInMs
    });
    await poller.poll();
    return poller;
  }

  /**
   * Description for Creates or updates a certificate and associates with key vault secret.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param certificateOrderName Name of the certificate order.
   * @param name Name of the certificate.
   * @param keyVaultCertificate Key vault certificate resource Id.
   * @param options The options parameters.
   */
  async beginCreateOrUpdateCertificateAndWait(
    resourceGroupName: string,
    certificateOrderName: string,
    name: string,
    keyVaultCertificate: AppServiceCertificateResource,
    options?: AppServiceCertificateOrdersCreateOrUpdateCertificateOptionalParams
  ): Promise<AppServiceCertificateOrdersCreateOrUpdateCertificateResponse> {
    const poller = await this.beginCreateOrUpdateCertificate(
      resourceGroupName,
      certificateOrderName,
      name,
      keyVaultCertificate,
      options
    );
    return poller.pollUntilDone();
  }

  /**
   * Description for Delete the certificate associated with a certificate order.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param certificateOrderName Name of the certificate order.
   * @param name Name of the certificate.
   * @param options The options parameters.
   */
  deleteCertificate(
    resourceGroupName: string,
    certificateOrderName: string,
    name: string,
    options?: AppServiceCertificateOrdersDeleteCertificateOptionalParams
  ): Promise<void> {
    return this.client.sendOperationRequest(
      { resourceGroupName, certificateOrderName, name, options },
      deleteCertificateOperationSpec
    );
  }

  /**
   * Description for Creates or updates a certificate and associates with key vault secret.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param certificateOrderName Name of the certificate order.
   * @param name Name of the certificate.
   * @param keyVaultCertificate Key vault certificate resource Id.
   * @param options The options parameters.
   */
  updateCertificate(
    resourceGroupName: string,
    certificateOrderName: string,
    name: string,
    keyVaultCertificate: AppServiceCertificatePatchResource,
    options?: AppServiceCertificateOrdersUpdateCertificateOptionalParams
  ): Promise<AppServiceCertificateOrdersUpdateCertificateResponse> {
    return this.client.sendOperationRequest(
      {
        resourceGroupName,
        certificateOrderName,
        name,
        keyVaultCertificate,
        options
      },
      updateCertificateOperationSpec
    );
  }

  /**
   * Description for Reissue an existing certificate order.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param certificateOrderName Name of the certificate order.
   * @param reissueCertificateOrderRequest Parameters for the reissue.
   * @param options The options parameters.
   */
  reissue(
    resourceGroupName: string,
    certificateOrderName: string,
    reissueCertificateOrderRequest: ReissueCertificateOrderRequest,
    options?: AppServiceCertificateOrdersReissueOptionalParams
  ): Promise<void> {
    return this.client.sendOperationRequest(
      {
        resourceGroupName,
        certificateOrderName,
        reissueCertificateOrderRequest,
        options
      },
      reissueOperationSpec
    );
  }

  /**
   * Description for Renew an existing certificate order.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param certificateOrderName Name of the certificate order.
   * @param renewCertificateOrderRequest Renew parameters
   * @param options The options parameters.
   */
  renew(
    resourceGroupName: string,
    certificateOrderName: string,
    renewCertificateOrderRequest: RenewCertificateOrderRequest,
    options?: AppServiceCertificateOrdersRenewOptionalParams
  ): Promise<void> {
    return this.client.sendOperationRequest(
      {
        resourceGroupName,
        certificateOrderName,
        renewCertificateOrderRequest,
        options
      },
      renewOperationSpec
    );
  }

  /**
   * Description for Resend certificate email.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param certificateOrderName Name of the certificate order.
   * @param options The options parameters.
   */
  resendEmail(
    resourceGroupName: string,
    certificateOrderName: string,
    options?: AppServiceCertificateOrdersResendEmailOptionalParams
  ): Promise<void> {
    return this.client.sendOperationRequest(
      { resourceGroupName, certificateOrderName, options },
      resendEmailOperationSpec
    );
  }

  /**
   * Resend domain verification ownership email containing steps on how to verify a domain for a given
   * certificate order
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param certificateOrderName Name of the certificate order.
   * @param nameIdentifier Email address
   * @param options The options parameters.
   */
  resendRequestEmails(
    resourceGroupName: string,
    certificateOrderName: string,
    nameIdentifier: NameIdentifier,
    options?: AppServiceCertificateOrdersResendRequestEmailsOptionalParams
  ): Promise<void> {
    return this.client.sendOperationRequest(
      { resourceGroupName, certificateOrderName, nameIdentifier, options },
      resendRequestEmailsOperationSpec
    );
  }

  /**
   * This method is used to obtain the site seal information for an issued certificate. A site seal is a
   * graphic that the certificate purchaser can embed on their web site to show their visitors
   * information about their SSL certificate. If a web site visitor clicks on the site seal image, a
   * pop-up page is displayed that contains detailed information about the SSL certificate. The site seal
   * token is used to link the site seal graphic image to the appropriate certificate details pop-up page
   * display when a user clicks on the site seal. The site seal images are expected to be static images
   * and hosted by the reseller, to minimize delays for customer page load times.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param certificateOrderName Name of the certificate order.
   * @param siteSealRequest Site seal request.
   * @param options The options parameters.
   */
  retrieveSiteSeal(
    resourceGroupName: string,
    certificateOrderName: string,
    siteSealRequest: SiteSealRequest,
    options?: AppServiceCertificateOrdersRetrieveSiteSealOptionalParams
  ): Promise<AppServiceCertificateOrdersRetrieveSiteSealResponse> {
    return this.client.sendOperationRequest(
      { resourceGroupName, certificateOrderName, siteSealRequest, options },
      retrieveSiteSealOperationSpec
    );
  }

  /**
   * Description for Verify domain ownership for this certificate order.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param certificateOrderName Name of the certificate order.
   * @param options The options parameters.
   */
  verifyDomainOwnership(
    resourceGroupName: string,
    certificateOrderName: string,
    options?: AppServiceCertificateOrdersVerifyDomainOwnershipOptionalParams
  ): Promise<void> {
    return this.client.sendOperationRequest(
      { resourceGroupName, certificateOrderName, options },
      verifyDomainOwnershipOperationSpec
    );
  }

  /**
   * Description for Retrieve the list of certificate actions.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param name Name of the certificate order.
   * @param options The options parameters.
   */
  retrieveCertificateActions(
    resourceGroupName: string,
    name: string,
    options?: AppServiceCertificateOrdersRetrieveCertificateActionsOptionalParams
  ): Promise<AppServiceCertificateOrdersRetrieveCertificateActionsResponse> {
    return this.client.sendOperationRequest(
      { resourceGroupName, name, options },
      retrieveCertificateActionsOperationSpec
    );
  }

  /**
   * Description for Retrieve email history.
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param name Name of the certificate order.
   * @param options The options parameters.
   */
  retrieveCertificateEmailHistory(
    resourceGroupName: string,
    name: string,
    options?: AppServiceCertificateOrdersRetrieveCertificateEmailHistoryOptionalParams
  ): Promise<
    AppServiceCertificateOrdersRetrieveCertificateEmailHistoryResponse
  > {
    return this.client.sendOperationRequest(
      { resourceGroupName, name, options },
      retrieveCertificateEmailHistoryOperationSpec
    );
  }

  /**
   * ListNext
   * @param nextLink The nextLink from the previous successful call to the List method.
   * @param options The options parameters.
   */
  private _listNext(
    nextLink: string,
    options?: AppServiceCertificateOrdersListNextOptionalParams
  ): Promise<AppServiceCertificateOrdersListNextResponse> {
    return this.client.sendOperationRequest(
      { nextLink, options },
      listNextOperationSpec
    );
  }

  /**
   * ListByResourceGroupNext
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param nextLink The nextLink from the previous successful call to the ListByResourceGroup method.
   * @param options The options parameters.
   */
  private _listByResourceGroupNext(
    resourceGroupName: string,
    nextLink: string,
    options?: AppServiceCertificateOrdersListByResourceGroupNextOptionalParams
  ): Promise<AppServiceCertificateOrdersListByResourceGroupNextResponse> {
    return this.client.sendOperationRequest(
      { resourceGroupName, nextLink, options },
      listByResourceGroupNextOperationSpec
    );
  }

  /**
   * ListCertificatesNext
   * @param resourceGroupName Name of the resource group to which the resource belongs.
   * @param certificateOrderName Name of the certificate order.
   * @param nextLink The nextLink from the previous successful call to the ListCertificates method.
   * @param options The options parameters.
   */
  private _listCertificatesNext(
    resourceGroupName: string,
    certificateOrderName: string,
    nextLink: string,
    options?: AppServiceCertificateOrdersListCertificatesNextOptionalParams
  ): Promise<AppServiceCertificateOrdersListCertificatesNextResponse> {
    return this.client.sendOperationRequest(
      { resourceGroupName, certificateOrderName, nextLink, options },
      listCertificatesNextOperationSpec
    );
  }
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);

const listOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/providers/Microsoft.CertificateRegistration/certificateOrders",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper: Mappers.AppServiceCertificateOrderCollection
    },
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  queryParameters: [Parameters.apiVersion],
  urlParameters: [Parameters.$host, Parameters.subscriptionId],
  headerParameters: [Parameters.accept],
  serializer
};
const validatePurchaseInformationOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/providers/Microsoft.CertificateRegistration/validateCertificateRegistrationInformation",
  httpMethod: "POST",
  responses: {
    204: {},
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  requestBody: Parameters.appServiceCertificateOrder,
  queryParameters: [Parameters.apiVersion],
  urlParameters: [Parameters.$host, Parameters.subscriptionId],
  headerParameters: [Parameters.accept, Parameters.contentType],
  mediaType: "json",
  serializer
};
const listByResourceGroupOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper: Mappers.AppServiceCertificateOrderCollection
    },
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  queryParameters: [Parameters.apiVersion],
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const getOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{certificateOrderName}",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper: Mappers.AppServiceCertificateOrder
    },
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  queryParameters: [Parameters.apiVersion],
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName,
    Parameters.certificateOrderName
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const createOrUpdateOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{certificateOrderName}",
  httpMethod: "PUT",
  responses: {
    200: {
      bodyMapper: Mappers.AppServiceCertificateOrder
    },
    201: {
      bodyMapper: Mappers.AppServiceCertificateOrder
    },
    202: {
      bodyMapper: Mappers.AppServiceCertificateOrder
    },
    204: {
      bodyMapper: Mappers.AppServiceCertificateOrder
    },
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  requestBody: Parameters.certificateDistinguishedName,
  queryParameters: [Parameters.apiVersion],
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName,
    Parameters.certificateOrderName
  ],
  headerParameters: [Parameters.accept, Parameters.contentType],
  mediaType: "json",
  serializer
};
const deleteOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{certificateOrderName}",
  httpMethod: "DELETE",
  responses: {
    200: {},
    204: {},
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  queryParameters: [Parameters.apiVersion],
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName,
    Parameters.certificateOrderName
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const updateOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{certificateOrderName}",
  httpMethod: "PATCH",
  responses: {
    200: {
      bodyMapper: Mappers.AppServiceCertificateOrder
    },
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  requestBody: Parameters.certificateDistinguishedName1,
  queryParameters: [Parameters.apiVersion],
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName,
    Parameters.certificateOrderName
  ],
  headerParameters: [Parameters.accept, Parameters.contentType],
  mediaType: "json",
  serializer
};
const listCertificatesOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{certificateOrderName}/certificates",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper: Mappers.AppServiceCertificateCollection
    },
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  queryParameters: [Parameters.apiVersion],
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName,
    Parameters.certificateOrderName
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const getCertificateOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{certificateOrderName}/certificates/{name}",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper: Mappers.AppServiceCertificateResource
    },
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  queryParameters: [Parameters.apiVersion],
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName,
    Parameters.certificateOrderName,
    Parameters.name
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const createOrUpdateCertificateOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{certificateOrderName}/certificates/{name}",
  httpMethod: "PUT",
  responses: {
    200: {
      bodyMapper: Mappers.AppServiceCertificateResource
    },
    201: {
      bodyMapper: Mappers.AppServiceCertificateResource
    },
    202: {
      bodyMapper: Mappers.AppServiceCertificateResource
    },
    204: {
      bodyMapper: Mappers.AppServiceCertificateResource
    },
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  requestBody: Parameters.keyVaultCertificate,
  queryParameters: [Parameters.apiVersion],
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName,
    Parameters.certificateOrderName,
    Parameters.name
  ],
  headerParameters: [Parameters.accept, Parameters.contentType],
  mediaType: "json",
  serializer
};
const deleteCertificateOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{certificateOrderName}/certificates/{name}",
  httpMethod: "DELETE",
  responses: {
    200: {},
    204: {},
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  queryParameters: [Parameters.apiVersion],
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName,
    Parameters.certificateOrderName,
    Parameters.name
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const updateCertificateOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{certificateOrderName}/certificates/{name}",
  httpMethod: "PATCH",
  responses: {
    200: {
      bodyMapper: Mappers.AppServiceCertificateResource
    },
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  requestBody: Parameters.keyVaultCertificate1,
  queryParameters: [Parameters.apiVersion],
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName,
    Parameters.certificateOrderName,
    Parameters.name
  ],
  headerParameters: [Parameters.accept, Parameters.contentType],
  mediaType: "json",
  serializer
};
const reissueOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{certificateOrderName}/reissue",
  httpMethod: "POST",
  responses: {
    204: {},
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  requestBody: Parameters.reissueCertificateOrderRequest,
  queryParameters: [Parameters.apiVersion],
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName,
    Parameters.certificateOrderName
  ],
  headerParameters: [Parameters.accept, Parameters.contentType],
  mediaType: "json",
  serializer
};
const renewOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{certificateOrderName}/renew",
  httpMethod: "POST",
  responses: {
    204: {},
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  requestBody: Parameters.renewCertificateOrderRequest,
  queryParameters: [Parameters.apiVersion],
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName,
    Parameters.certificateOrderName
  ],
  headerParameters: [Parameters.accept, Parameters.contentType],
  mediaType: "json",
  serializer
};
const resendEmailOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{certificateOrderName}/resendEmail",
  httpMethod: "POST",
  responses: {
    204: {},
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  queryParameters: [Parameters.apiVersion],
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName,
    Parameters.certificateOrderName
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const resendRequestEmailsOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{certificateOrderName}/resendRequestEmails",
  httpMethod: "POST",
  responses: {
    204: {},
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  requestBody: Parameters.nameIdentifier,
  queryParameters: [Parameters.apiVersion],
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName,
    Parameters.certificateOrderName
  ],
  headerParameters: [Parameters.accept, Parameters.contentType],
  mediaType: "json",
  serializer
};
const retrieveSiteSealOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{certificateOrderName}/retrieveSiteSeal",
  httpMethod: "POST",
  responses: {
    200: {
      bodyMapper: Mappers.SiteSeal
    },
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  requestBody: Parameters.siteSealRequest,
  queryParameters: [Parameters.apiVersion],
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName,
    Parameters.certificateOrderName
  ],
  headerParameters: [Parameters.accept, Parameters.contentType],
  mediaType: "json",
  serializer
};
const verifyDomainOwnershipOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{certificateOrderName}/verifyDomainOwnership",
  httpMethod: "POST",
  responses: {
    204: {},
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  queryParameters: [Parameters.apiVersion],
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName,
    Parameters.certificateOrderName
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const retrieveCertificateActionsOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{name}/retrieveCertificateActions",
  httpMethod: "POST",
  responses: {
    200: {
      bodyMapper: {
        type: {
          name: "Sequence",
          element: {
            type: { name: "Composite", className: "CertificateOrderAction" }
          }
        }
      }
    },
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  queryParameters: [Parameters.apiVersion],
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName,
    Parameters.name
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const retrieveCertificateEmailHistoryOperationSpec: coreClient.OperationSpec = {
  path:
    "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{name}/retrieveEmailHistory",
  httpMethod: "POST",
  responses: {
    200: {
      bodyMapper: {
        type: {
          name: "Sequence",
          element: {
            type: { name: "Composite", className: "CertificateEmail" }
          }
        }
      }
    },
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  queryParameters: [Parameters.apiVersion],
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName,
    Parameters.name
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const listNextOperationSpec: coreClient.OperationSpec = {
  path: "{nextLink}",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper: Mappers.AppServiceCertificateOrderCollection
    },
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.nextLink
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const listByResourceGroupNextOperationSpec: coreClient.OperationSpec = {
  path: "{nextLink}",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper: Mappers.AppServiceCertificateOrderCollection
    },
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName,
    Parameters.nextLink
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const listCertificatesNextOperationSpec: coreClient.OperationSpec = {
  path: "{nextLink}",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper: Mappers.AppServiceCertificateCollection
    },
    default: {
      bodyMapper: Mappers.DefaultErrorResponse
    }
  },
  urlParameters: [
    Parameters.$host,
    Parameters.subscriptionId,
    Parameters.resourceGroupName,
    Parameters.certificateOrderName,
    Parameters.nextLink
  ],
  headerParameters: [Parameters.accept],
  serializer
};
