// 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 DatabaseColumns operations. */
export class DatabaseColumnsImpl {
    client;
    /**
     * Initialize a new instance of the class DatabaseColumns class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * List database columns
     * @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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param options The options parameters.
     */
    listByDatabase(resourceGroupName, serverName, databaseName, options) {
        const iter = this.listByDatabasePagingAll(resourceGroupName, serverName, databaseName, 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.listByDatabasePagingPage(resourceGroupName, serverName, databaseName, options, settings);
            },
        };
    }
    async *listByDatabasePagingPage(resourceGroupName, serverName, databaseName, options, settings) {
        let result;
        let continuationToken = settings?.continuationToken;
        if (!continuationToken) {
            result = await this._listByDatabase(resourceGroupName, serverName, databaseName, options);
            let page = result.value || [];
            continuationToken = result.nextLink;
            setContinuationToken(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listByDatabaseNext(resourceGroupName, serverName, databaseName, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            setContinuationToken(page, continuationToken);
            yield page;
        }
    }
    async *listByDatabasePagingAll(resourceGroupName, serverName, databaseName, options) {
        for await (const page of this.listByDatabasePagingPage(resourceGroupName, serverName, databaseName, options)) {
            yield* page;
        }
    }
    /**
     * List database columns
     * @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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param schemaName The name of the schema.
     * @param tableName The name of the table.
     * @param options The options parameters.
     */
    listByTable(resourceGroupName, serverName, databaseName, schemaName, tableName, options) {
        const iter = this.listByTablePagingAll(resourceGroupName, serverName, databaseName, schemaName, tableName, 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.listByTablePagingPage(resourceGroupName, serverName, databaseName, schemaName, tableName, options, settings);
            },
        };
    }
    async *listByTablePagingPage(resourceGroupName, serverName, databaseName, schemaName, tableName, options, settings) {
        let result;
        let continuationToken = settings?.continuationToken;
        if (!continuationToken) {
            result = await this._listByTable(resourceGroupName, serverName, databaseName, schemaName, tableName, options);
            let page = result.value || [];
            continuationToken = result.nextLink;
            setContinuationToken(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listByTableNext(resourceGroupName, serverName, databaseName, schemaName, tableName, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            setContinuationToken(page, continuationToken);
            yield page;
        }
    }
    async *listByTablePagingAll(resourceGroupName, serverName, databaseName, schemaName, tableName, options) {
        for await (const page of this.listByTablePagingPage(resourceGroupName, serverName, databaseName, schemaName, tableName, options)) {
            yield* page;
        }
    }
    /**
     * List database columns
     * @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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param options The options parameters.
     */
    _listByDatabase(resourceGroupName, serverName, databaseName, options) {
        return this.client.sendOperationRequest({ resourceGroupName, serverName, databaseName, options }, listByDatabaseOperationSpec);
    }
    /**
     * List database columns
     * @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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param schemaName The name of the schema.
     * @param tableName The name of the table.
     * @param options The options parameters.
     */
    _listByTable(resourceGroupName, serverName, databaseName, schemaName, tableName, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            databaseName,
            schemaName,
            tableName,
            options,
        }, listByTableOperationSpec);
    }
    /**
     * Get database column
     * @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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param schemaName The name of the schema.
     * @param tableName The name of the table.
     * @param columnName The name of the column.
     * @param options The options parameters.
     */
    get(resourceGroupName, serverName, databaseName, schemaName, tableName, columnName, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            databaseName,
            schemaName,
            tableName,
            columnName,
            options,
        }, getOperationSpec);
    }
    /**
     * ListByDatabaseNext
     * @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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param nextLink The nextLink from the previous successful call to the ListByDatabase method.
     * @param options The options parameters.
     */
    _listByDatabaseNext(resourceGroupName, serverName, databaseName, nextLink, options) {
        return this.client.sendOperationRequest({ resourceGroupName, serverName, databaseName, nextLink, options }, listByDatabaseNextOperationSpec);
    }
    /**
     * ListByTableNext
     * @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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param schemaName The name of the schema.
     * @param tableName The name of the table.
     * @param nextLink The nextLink from the previous successful call to the ListByTable method.
     * @param options The options parameters.
     */
    _listByTableNext(resourceGroupName, serverName, databaseName, schemaName, tableName, nextLink, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            databaseName,
            schemaName,
            tableName,
            nextLink,
            options,
        }, listByTableNextOperationSpec);
    }
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listByDatabaseOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/columns",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.DatabaseColumnListResult,
        },
        default: {},
    },
    queryParameters: [
        Parameters.apiVersion3,
        Parameters.schema,
        Parameters.table,
        Parameters.column,
        Parameters.orderBy,
        Parameters.skiptoken,
    ],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByTableOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.DatabaseColumnListResult,
        },
        default: {},
    },
    queryParameters: [Parameters.filter1, Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
        Parameters.schemaName,
        Parameters.tableName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const getOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.DatabaseColumn,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
        Parameters.schemaName,
        Parameters.tableName,
        Parameters.columnName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByDatabaseNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.DatabaseColumnListResult,
        },
        default: {},
    },
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
        Parameters.nextLink,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByTableNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.DatabaseColumnListResult,
        },
        default: {},
    },
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
        Parameters.nextLink,
        Parameters.schemaName,
        Parameters.tableName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
//# sourceMappingURL=databaseColumns.js.map