"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RestWebservice = void 0;
var bfast_1 = require("bfast");
var http_status_codes_1 = __importDefault(require("http-status-codes"));
var RestWebservice = (function () {
    function RestWebservice() {
    }
    RestWebservice.prototype.rulesV2 = function (prefix, securityController, restController, rulesController, authController, updateRuleController, databaseController, storageController, authAdapter, filesAdapter, databaseAdapter, options) {
        if (prefix === void 0) { prefix = '/'; }
        return bfast_1.functions().onPostHttpRequest(prefix + "v2", [
            function (rq, rs, n) { return restController.verifyMethod(rq, rs, n); },
            function (rq, rs, n) { return restController.verifyBodyData(rq, rs, n); },
            function (rq, rs, n) { return restController
                .verifyApplicationId(rq, rs, n, options); },
            function (rq, rs, n) { return restController
                .verifyToken(rq, rs, n, securityController, options); },
            function (rq, rs, n) { return restController
                .handleRuleBlocks(rq, rs, n, rulesController, authController, updateRuleController, databaseController, securityController, storageController, authAdapter, databaseAdapter, filesAdapter, options); }
        ]);
    };
    RestWebservice.prototype.authJwk = function (options) {
        return bfast_1.functions().onHttpRequest('/jwk', function (request, response) {
            if (options.rsaPublicKeyInJson) {
                response.status(200).json(options.rsaPublicKeyInJson);
            }
            else {
                response.status(http_status_codes_1.default.EXPECTATION_FAILED).json({ message: 'fail to retrieve public key' });
            }
        });
    };
    return RestWebservice;
}());
exports.RestWebservice = RestWebservice;
