// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { setContinuationToken } from "../pagingHelper.js";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers.js";
import * as Parameters from "../models/parameters.js";
/// <reference lib="esnext.asynciterable" />
/** Class containing ManagedDatabaseQueries operations. */
export class ManagedDatabaseQueriesImpl {
    client;
    /**
     * Initialize a new instance of the class ManagedDatabaseQueries class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * Get query execution statistics by query id.
     * @param resourceGroupName The name of the resource group that contains the resource. You can obtain
     *                          this value from the Azure Resource Manager API or the portal.
     * @param managedInstanceName The name of the managed instance.
     * @param databaseName The name of the database.
     * @param queryId
     * @param options The options parameters.
     */
    listByQuery(resourceGroupName, managedInstanceName, databaseName, queryId, options) {
        const iter = this.listByQueryPagingAll(resourceGroupName, managedInstanceName, databaseName, queryId, options);
        return {
            next() {
                return iter.next();
            },
            [Symbol.asyncIterator]() {
                return this;
            },
            byPage: (settings) => {
                if (settings?.maxPageSize) {
                    throw new Error("maxPageSize is not supported by this operation.");
                }
                return this.listByQueryPagingPage(resourceGroupName, managedInstanceName, databaseName, queryId, options, settings);
            },
        };
    }
    async *listByQueryPagingPage(resourceGroupName, managedInstanceName, databaseName, queryId, options, settings) {
        let result;
        let continuationToken = settings?.continuationToken;
        if (!continuationToken) {
            result = await this._listByQuery(resourceGroupName, managedInstanceName, databaseName, queryId, options);
            let page = result.value || [];
            continuationToken = result.nextLink;
            setContinuationToken(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listByQueryNext(resourceGroupName, managedInstanceName, databaseName, queryId, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            setContinuationToken(page, continuationToken);
            yield page;
        }
    }
    async *listByQueryPagingAll(resourceGroupName, managedInstanceName, databaseName, queryId, options) {
        for await (const page of this.listByQueryPagingPage(resourceGroupName, managedInstanceName, databaseName, queryId, options)) {
            yield* page;
        }
    }
    /**
     * Get query by query id.
     * @param resourceGroupName The name of the resource group that contains the resource. You can obtain
     *                          this value from the Azure Resource Manager API or the portal.
     * @param managedInstanceName The name of the managed instance.
     * @param databaseName The name of the database.
     * @param queryId
     * @param options The options parameters.
     */
    get(resourceGroupName, managedInstanceName, databaseName, queryId, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            managedInstanceName,
            databaseName,
            queryId,
            options,
        }, getOperationSpec);
    }
    /**
     * Get query execution statistics by query id.
     * @param resourceGroupName The name of the resource group that contains the resource. You can obtain
     *                          this value from the Azure Resource Manager API or the portal.
     * @param managedInstanceName The name of the managed instance.
     * @param databaseName The name of the database.
     * @param queryId
     * @param options The options parameters.
     */
    _listByQuery(resourceGroupName, managedInstanceName, databaseName, queryId, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            managedInstanceName,
            databaseName,
            queryId,
            options,
        }, listByQueryOperationSpec);
    }
    /**
     * ListByQueryNext
     * @param resourceGroupName The name of the resource group that contains the resource. You can obtain
     *                          this value from the Azure Resource Manager API or the portal.
     * @param managedInstanceName The name of the managed instance.
     * @param databaseName The name of the database.
     * @param queryId
     * @param nextLink The nextLink from the previous successful call to the ListByQuery method.
     * @param options The options parameters.
     */
    _listByQueryNext(resourceGroupName, managedInstanceName, databaseName, queryId, nextLink, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            managedInstanceName,
            databaseName,
            queryId,
            nextLink,
            options,
        }, listByQueryNextOperationSpec);
    }
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const getOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/queries/{queryId}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.ManagedInstanceQuery,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.databaseName,
        Parameters.managedInstanceName,
        Parameters.queryId,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByQueryOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/queries/{queryId}/statistics",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.ManagedInstanceQueryStatistics,
        },
        default: {},
    },
    queryParameters: [
        Parameters.apiVersion3,
        Parameters.startTime,
        Parameters.endTime,
        Parameters.interval,
    ],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.databaseName,
        Parameters.managedInstanceName,
        Parameters.queryId,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByQueryNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.ManagedInstanceQueryStatistics,
        },
        default: {},
    },
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.databaseName,
        Parameters.nextLink,
        Parameters.managedInstanceName,
        Parameters.queryId,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
//# sourceMappingURL=managedDatabaseQueries.js.map