"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 bfastnode_1 = require("bfastnode");
var http_status_codes_1 = __importDefault(require("http-status-codes"));
var RestWebservice = (function () {
    function RestWebservice(restController, options) {
        this.restController = restController;
        this.options = options;
    }
    RestWebservice.prototype.rulesV2 = function (prefix) {
        var _this = this;
        if (prefix === void 0) { prefix = '/'; }
        return bfastnode_1.BFast.functions().onPostHttpRequest(prefix + "v2", [
            function (request, response, next) { return _this.restController.verifyMethod(request, response, next); },
            function (request, response, next) { return _this.restController.verifyBodyData(request, response, next); },
            function (request, response, next) { return _this.restController.verifyApplicationId(request, response, next); },
            function (request, response, next) { return _this.restController.verifyToken(request, response, next); },
            function (request, response, next) { return _this.restController.handleRuleBlocks(request, response, next); }
        ]);
    };
    RestWebservice.prototype.authJwk = function () {
        var _this = this;
        return bfastnode_1.BFast.functions().onHttpRequest('/jwk', function (request, response) {
            if (_this.options.rsaPublicKeyInJson) {
                response.status(200).json(_this.options.rsaPublicKeyInJson);
            }
            else {
                response.status(http_status_codes_1.default.EXPECTATION_FAILED).json({ message: 'fail to retrieve public key' });
            }
        });
    };
    return RestWebservice;
}());
exports.RestWebservice = RestWebservice;
