/*
 * 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 { __asyncDelegator, __asyncGenerator, __asyncValues, __await } from "tslib";
import { setContinuationToken } from "../pagingHelper";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers";
import * as Parameters from "../models/parameters";
/// <reference lib="esnext.asynciterable" />
/** Class containing ContainerAppsRevisions operations. */
export class ContainerAppsRevisionsImpl {
    /**
     * Initialize a new instance of the class ContainerAppsRevisions class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * Get the Revisions for a given Container App.
     * @param resourceGroupName Name of the resource group to which the resource belongs.
     * @param containerAppName Name of the Container App for which Revisions are needed.
     * @param options The options parameters.
     */
    listRevisions(resourceGroupName, containerAppName, options) {
        const iter = this.listRevisionsPagingAll(resourceGroupName, containerAppName, options);
        return {
            next() {
                return iter.next();
            },
            [Symbol.asyncIterator]() {
                return this;
            },
            byPage: (settings) => {
                if (settings === null || settings === void 0 ? void 0 : settings.maxPageSize) {
                    throw new Error("maxPageSize is not supported by this operation.");
                }
                return this.listRevisionsPagingPage(resourceGroupName, containerAppName, options, settings);
            }
        };
    }
    listRevisionsPagingPage(resourceGroupName, containerAppName, options, settings) {
        return __asyncGenerator(this, arguments, function* listRevisionsPagingPage_1() {
            let result;
            let continuationToken = settings === null || settings === void 0 ? void 0 : settings.continuationToken;
            if (!continuationToken) {
                result = yield __await(this._listRevisions(resourceGroupName, containerAppName, options));
                let page = result.value || [];
                continuationToken = result.nextLink;
                setContinuationToken(page, continuationToken);
                yield yield __await(page);
            }
            while (continuationToken) {
                result = yield __await(this._listRevisionsNext(resourceGroupName, containerAppName, continuationToken, options));
                continuationToken = result.nextLink;
                let page = result.value || [];
                setContinuationToken(page, continuationToken);
                yield yield __await(page);
            }
        });
    }
    listRevisionsPagingAll(resourceGroupName, containerAppName, options) {
        return __asyncGenerator(this, arguments, function* listRevisionsPagingAll_1() {
            var _a, e_1, _b, _c;
            try {
                for (var _d = true, _e = __asyncValues(this.listRevisionsPagingPage(resourceGroupName, containerAppName, options)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
                    _c = _f.value;
                    _d = false;
                    const page = _c;
                    yield __await(yield* __asyncDelegator(__asyncValues(page)));
                }
            }
            catch (e_1_1) { e_1 = { error: e_1_1 }; }
            finally {
                try {
                    if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
                }
                finally { if (e_1) throw e_1.error; }
            }
        });
    }
    /**
     * Get the Revisions for a given Container App.
     * @param resourceGroupName Name of the resource group to which the resource belongs.
     * @param containerAppName Name of the Container App for which Revisions are needed.
     * @param options The options parameters.
     */
    _listRevisions(resourceGroupName, containerAppName, options) {
        return this.client.sendOperationRequest({ resourceGroupName, containerAppName, options }, listRevisionsOperationSpec);
    }
    /**
     * Get a revision of a Container App.
     * @param resourceGroupName Name of the resource group to which the resource belongs.
     * @param containerAppName Name of the Container App.
     * @param name Name of the Container App Revision.
     * @param options The options parameters.
     */
    getRevision(resourceGroupName, containerAppName, name, options) {
        return this.client.sendOperationRequest({ resourceGroupName, containerAppName, name, options }, getRevisionOperationSpec);
    }
    /**
     * Activates a revision for a Container App
     * @param resourceGroupName Name of the resource group to which the resource belongs.
     * @param containerAppName Name of the Container App.
     * @param name Name of the Container App Revision to activate
     * @param options The options parameters.
     */
    activateRevision(resourceGroupName, containerAppName, name, options) {
        return this.client.sendOperationRequest({ resourceGroupName, containerAppName, name, options }, activateRevisionOperationSpec);
    }
    /**
     * Deactivates a revision for a Container App
     * @param resourceGroupName Name of the resource group to which the resource belongs.
     * @param containerAppName Name of the Container App.
     * @param name Name of the Container App Revision to deactivate
     * @param options The options parameters.
     */
    deactivateRevision(resourceGroupName, containerAppName, name, options) {
        return this.client.sendOperationRequest({ resourceGroupName, containerAppName, name, options }, deactivateRevisionOperationSpec);
    }
    /**
     * Restarts a revision for a Container App
     * @param resourceGroupName Name of the resource group to which the resource belongs.
     * @param containerAppName Name of the Container App.
     * @param name Name of the Container App Revision to restart
     * @param options The options parameters.
     */
    restartRevision(resourceGroupName, containerAppName, name, options) {
        return this.client.sendOperationRequest({ resourceGroupName, containerAppName, name, options }, restartRevisionOperationSpec);
    }
    /**
     * ListRevisionsNext
     * @param resourceGroupName Name of the resource group to which the resource belongs.
     * @param containerAppName Name of the Container App for which Revisions are needed.
     * @param nextLink The nextLink from the previous successful call to the ListRevisions method.
     * @param options The options parameters.
     */
    _listRevisionsNext(resourceGroupName, containerAppName, nextLink, options) {
        return this.client.sendOperationRequest({ resourceGroupName, containerAppName, nextLink, options }, listRevisionsNextOperationSpec);
    }
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listRevisionsOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/containerApps/{containerAppName}/revisions",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.RevisionCollection
        },
        default: {
            bodyMapper: Mappers.DefaultErrorResponse
        }
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.containerAppName
    ],
    headerParameters: [Parameters.accept],
    serializer
};
const getRevisionOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/containerApps/{containerAppName}/revisions/{name}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.Revision
        },
        default: {
            bodyMapper: Mappers.DefaultErrorResponse
        }
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.name,
        Parameters.containerAppName
    ],
    headerParameters: [Parameters.accept],
    serializer
};
const activateRevisionOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/containerApps/{containerAppName}/revisions/{name}/activate",
    httpMethod: "POST",
    responses: {
        200: {},
        default: {
            bodyMapper: Mappers.DefaultErrorResponse
        }
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.name,
        Parameters.containerAppName
    ],
    headerParameters: [Parameters.accept],
    serializer
};
const deactivateRevisionOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/containerApps/{containerAppName}/revisions/{name}/deactivate",
    httpMethod: "POST",
    responses: {
        200: {},
        default: {
            bodyMapper: Mappers.DefaultErrorResponse
        }
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.name,
        Parameters.containerAppName
    ],
    headerParameters: [Parameters.accept],
    serializer
};
const restartRevisionOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/containerApps/{containerAppName}/revisions/{name}/restart",
    httpMethod: "POST",
    responses: {
        200: {},
        default: {
            bodyMapper: Mappers.DefaultErrorResponse
        }
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.name,
        Parameters.containerAppName
    ],
    headerParameters: [Parameters.accept],
    serializer
};
const listRevisionsNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.RevisionCollection
        },
        default: {
            bodyMapper: Mappers.DefaultErrorResponse
        }
    },
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.nextLink,
        Parameters.containerAppName
    ],
    headerParameters: [Parameters.accept],
    serializer
};
//# sourceMappingURL=containerAppsRevisions.js.map